[TIP] Can pytest identify python code that has no test

DZIOBEK, JOE jd5948 at att.com
Fri Jan 4 11:31:17 PST 2019


Hi Ned,

Yes, my tox.ini file is as described earlier:
commands =
    coverage run -m --source=. pytest --ignore=virtualenv-15.1.0/ --ignore=.tox
    coverage report -m --omit=.tox/*

For additional debugging, I added another py file to my root folder, so now I have:

script.py
test_script.py
scriptB2.py ( which does not have an associated test script! )

Then a subfolder (actually 5 levels deep, see below)
scriptA.py
test_scriptA.py
scriptB.py ( which does not have an associated test script! )

Executing the tox command again, I now get an improved picture:
Name                                                                      Stmts   Miss  Cover   Missing
-------------------------------------------------------------------------------------------------------
sub/sub2/sub3/sub4/sub5/scriptA.py            2      0   100%
sub/sub2/sub3/sub4/sub5/test_scriptA.py       3      0   100%
script.py                                                                     4      1    75%   3
scriptB2.py                                                          142    142     0%   3-322
test_script.py                                                                3      0   100%
-------------------------------------------------------------------------------------------------------

So we found the UNTESTED scriptB2.py in root folder – exactly what we want.
It did not find the UNTESTED script.py in the deeper folder.
Any ideas? BTW, I don’t have any __init__.py files in any folder.

PS: Bruno, your idea with adding the import to the __init__.py file is good, but requires someone to update that file, probably the same person that forgot to write the test.py;

Thanks for your help,
Regards - Joe

From: testing-in-python-bounces at lists.idyll.org [mailto:testing-in-python-bounces at lists.idyll.org] On Behalf Of Ned Batchelder
Sent: Friday, January 04, 2019 11:59 AM
To: testing-in-python at lists.idyll.org
Subject: Re: [TIP] Can pytest identify python code that has no test


Joe, since you have specified "--source=.", coverage will search your tree for importable Python files, and report on them even if they are never imported.  So you are already doing the right thing. I'm not sure why it wouldn't show you that file.  Are you sure you are running the commands you showed?

--Ned.
On 1/4/19 11:42 AM, Bruno Oliveira wrote:
Hi Joe,
On Fri, Dec 21, 2018 at 5:06 PM DZIOBEK, JOE <jd5948 at att.com<mailto:jd5948 at att.com>> wrote:
Is there a way to have this file included in the report?

You are not seeing coverage information for scriptB.py not because it does not have an associated test file, but because it was never imported during the run (I'm assuming).

One way to have it to appear on the report is to import scriptB on your __init__.py file, this way its coverage will be tracked.

Hope this helps,
Bruno



_______________________________________________

testing-in-python mailing list

testing-in-python at lists.idyll.org<mailto:testing-in-python at lists.idyll.org>

http://lists.idyll.org/listinfo/testing-in-python<https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.idyll.org_listinfo_testing-2Din-2Dpython&d=DwMDaQ&c=LFYZ-o9_HUMeMTSQicvjIg&r=HqXpIkByGFw24obqdoDmDw&m=pzoCcDdzPm0JZq_KFlE4flon2ylEw7Wn8WlOaZn3xgc&s=LZn-2waQlWLtBfotLco8eIxWEeII9mXtCXPlJ8rxaos&e=>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20190104/b6b3b604/attachment-0001.htm>


More information about the testing-in-python mailing list