[TIP] check for actual assertions in tests

Alexandre Conrad alexandre.conrad at gmail.com
Fri Nov 14 11:17:38 PST 2014


Hi Ian,

Thanks for your response. That's what I thought too. What you said makes
sense and using an AST tree would probably end up finding some assert
statement down the road (or if not, flag the test).

Such tool would definitely be handy test linting tool. I'll look around
pypi otherwise I may take a stab at implementing it depending on my spare
bandwidth.

Best,


2014-11-14 10:51 GMT-08:00 Ian Cordasco <graffatcolmingov at gmail.com>:

> 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...
> eventually.
>
> Cheers,
> Ian
>



-- 
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20141114/5d0ed946/attachment.htm>


More information about the testing-in-python mailing list