GithubHelp home page GithubHelp logo

Comments (2)

m-burst avatar m-burst commented on July 28, 2024

Hi @jenstroeger,

I'm not sure I agree with this.
There might be code actually raising Exception (which is a bad practice by itself, but out of the scope here), so the tests will also need to catch Exception. This can also happen in third-party code, outside of the test author's control.
There already is PT011 which would force test authors to specify the match parameter for the exceptions considered too broad.

from flake8-pytest-style.

jenstroeger avatar jenstroeger commented on July 28, 2024

Thank you @m-burst for your response, but I disagree.

There might be code actually raising Exception […], so the tests will also need to catch Exception.

Indeed that is correct, and in that case the flake8 warning should be suppressed with a # noqa comment — just like the pylint warning should be suppressed to clarify intent.

(which is a bad practice by itself, but out of the scope here)

I think it’s quite in scope of flake8 to encourage good coding and testing practices. Not warning at all, I think, continues to encourage bad practices.

Furthermore, by catching & testing for broad Exception a test may capture unexpected errors and therefore create a false negative. In fact, I opened this issue because I’ve seen exactly that happening a little too often and I am tired of asking people to not use Exception. Help from a tool would drive home the importance of narrowing test cases to only the necessary exceptions.

There already is PT011 which […]

That is assuming that people pass a string to an exception, which is not always the case either.

from flake8-pytest-style.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.