dosisod/refurb

Enable `--cov-branch` in `pytest`

sobolevn opened this issue · 1 comments

Coverage has a nice addition to make it even more strict: branch mode https://coverage.readthedocs.io/en/latest/branch.html

You can enable it with --cov-branch in addopts or as branch = true in [tool.coverage.run]

Right now it will give these results:

» make test
pytest
=================================== test session starts ===================================
platform darwin -- Python 3.11.3, pytest-7.4.0, pluggy-1.2.0
rootdir: /Users/sobolev/Desktop/refurb
configfile: pyproject.toml
testpaths: test
plugins: cov-4.1.0, anyio-3.7.1
collected 125 items                                                                       

test/test_arg_parsing.py .......................................................... [ 46%]
........                                                                            [ 52%]
test/test_check_formatting.py .                                                     [ 53%]
test/test_checks.py ......................                                          [ 71%]
test/test_explain.py ...                                                            [ 73%]
test/test_gen.py ...                                                                [ 76%]
test/test_github_annotations.py ..                                                  [ 77%]
test/test_loader.py .......                                                         [ 83%]
test/test_main.py .............s.....                                               [ 98%]
test/test_visitor.py ..                                                             [100%]

---------- coverage: platform darwin, python 3.11.3-final-0 ----------
Name                                             Stmts   Miss Branch BrPart  Cover   Missing
--------------------------------------------------------------------------------------------
refurb/checks/common.py                            103      0     64      2    99%   48->51, 63->exit
refurb/checks/flow/no_trailing_continue.py          32      0     20      1    98%   95->exit
refurb/checks/flow/no_trailing_return.py            32      0     20      1    98%   90->exit
refurb/checks/function/use_implicit_default.py      83      0     58      2    99%   172->168, 185->183
refurb/checks/pathlib/no_join.py                    28      0     10      1    97%   61->70
refurb/checks/pathlib/read_text.py                  25      0     12      1    97%   75->70
refurb/checks/readability/no_len_cmp.py             75      0     44      1    99%   222->exit
refurb/checks/readability/no_or_default.py          41      0     22      1    98%   94->exit
refurb/checks/readability/use_dict_union.py         36      0     16      1    98%   45->exit
refurb/checks/readability/use_operators.py          19      0     10      2    93%   110->exit, 132->exit
refurb/checks/regex/use_long_flag.py                14      0      6      1    95%   50->exit
refurb/loader.py                                   103      0     62      2    99%   37->41, 178->174
refurb/main.py                                     122      0     53      2    99%   96->95, 160->159
--------------------------------------------------------------------------------------------
TOTAL                                             2448      0   1117     18    99%

95 files skipped due to complete coverage.
Coverage HTML written to dir htmlcov

FAIL Required test coverage of 100% not reached. Total coverage: 99.50%

============================= 124 passed, 1 skipped in 21.87s =============================

Thanks for bringing this up, getting 100% branch coverage has been on my list. Most of these seem pretty trivial to fix, so I should be able to update the tests by the end of the week.