neithere / argh

An argparse wrapper that doesn't make you say "argh" each time you deal with it.
http://argh.rtfd.org
GNU Lesser General Public License v3.0
369 stars 55 forks source link

Test coverage reported as <100% when argcomplete is installed #187

Closed mtelka closed 11 months ago

mtelka commented 1 year ago

I'm packaging argh for OpenIndiana and during testing of version 0.29.3 I noticed the coverage fails:

---------- coverage: platform sunos5, python 3.9.16-final-0 ----------
Name                      Stmts   Miss  Cover
---------------------------------------------
src/argh/__init__.py          7      0   100%
src/argh/assembling.py      154      0   100%
src/argh/completion.py       16      2    88%
src/argh/constants.py        30      0   100%
src/argh/decorators.py       31      0   100%
src/argh/dispatching.py     126      0   100%
src/argh/exceptions.py        7      0   100%
src/argh/helpers.py          21      0   100%
src/argh/interaction.py      27      0   100%
src/argh/io.py                2      0   100%
src/argh/utils.py            24      0   100%
---------------------------------------------
TOTAL                       445      2    99%

FAIL Required test coverage of 100% not reached. Total coverage: 99.55%
================== 111 passed, 3 xfailed, 4 warnings in 1.34s ==================
neithere commented 1 year ago

Hmm. The latest build in CI for Python 3.9 says:

platform linux -- Python 3.9.17, pytest-7.4.1, pluggy-1.3.0 ... Required test coverage of 100% reached. Total coverage: 100.00%

Not sure if the difference is related to sunos5. Do you have the results for Argh 0.28 in the same environment? Do you have more detailed information about the missed statements?

This argh.completion where coverage is missing is a tiny module with barely any logic, so it's probably either sh being used instead of bash in that environment, or argcomplete not being installed.

mtelka commented 1 year ago

The more complete report shows these two lines as missing:

70 except ImportError: 
71     argcomplete = None
neithere commented 1 year ago

Hm, interesting. Looks like in your environment argcomplete is present and in the default CI environments for Argh it's not.

It may be a good idea to add a tox env with extras=completion.

OTOH, the only thing it would check is whether COMPLETION_ENABLED is set to the correct value depending on whether it was possible to import argcomplete. It's such a trivial bit of logic that I'm rather leaning towards adding # pragma: no cover to these lines that you've mentioned. The behaviour with and without argcomplete is tested with a mock in any case.

mtelka commented 1 year ago

Yes, exactly. The argcomplete is installed here.

neithere commented 11 months ago

I've excluded that line from coverage, it really makes no sense to add a whole tox env to test that pretty obvious bit of code. Thanks for reporting!