[TIP] check for actual assertions in tests

Ian Cordasco graffatcolmingov at gmail.com
Fri Nov 14 10:51:09 PST 2014

On Fri, Nov 14, 2014 at 12:00 PM, Alexandre Conrad
<alexandre.conrad at gmail.com> wrote:
> Hi list,
> I was wondering if you knew a tool that would ensure that tests contain some
> kind of assertions e.g., an assert statement or a call to a method such as
> TestCase.assertTrue().
> I would love to be able to run something like "py.test
> --fail-missing-assert" which would fail a test if the user accidentally did
> "data == expected_data" rather than "assert data == expected_data".
> Tests without any assertions are the worst because the number of tests and
> code coverage grows providing a false sense of satisfaction when really the
> test would have failed in the first place if a proper assertion was written.
> Any thoughts on this?
> Thanks,
> --
> Alex
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

Hey Alex,

I don't know how practical this would be. You'd essentially have to do
a whole other pass over the code (either using static or AST analysis)
to determine if an assertion wasn't made. The reason for this is that
a lot of test suites write helper methods to try to DRY up their tests
so a test may end with self.verifyFooBarBaz(some, params) which calls
another method. Static analysis as a first pass would flag that test
method, but using the AST you might be able to find the assertion...


More information about the testing-in-python mailing list