Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_pytest.assertion.reinterpret.AssertionError: Test coverage should never be None #84

Closed
msabramo opened this issue Aug 21, 2015 · 10 comments

Comments

@msabramo
Copy link
Contributor

With pytest-cov 2.0, I'm getting:

_pytest.assertion.reinterpret.AssertionError: Test coverage should never be `None`

On the same projects with pytest-cov 1.8.1, it works fine.

Example command-line:

$ tox -e py27
...
------------------------------------------------------------------------------------------------------------------------------- generated xml file: /home/monkey/ce402c011ae38dae/junit.xml --------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------- coverage: platform linux2, python 2.7.6-final-0 --------------------------------------------------------------------------------------------------------------------------------------
Name                                                    Stmts   Miss  Cover   Missing
-------------------------------------------------------------------------------------
usersvc/__init__                                          196      0   100%
usersvc/appstatus                                          27     21    22%   9-16, 20-27, 31-38
usersvc/lib/__init__                                        2      0   100%
usersvc/lib/cache                                           6      0   100%
...
Traceback (most recent call last):
  File ".tox/py27/bin/py.test", line 11, in <module>
    sys.exit(main())
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/config.py", line 41, in main
    return config.hook.pytest_cmdline_main(config=config)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
    return self._docall(self.methods, kwargs)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
    firstresult=self.firstresult).execute()
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
    res = method(*args)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/main.py", line 116, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/main.py", line 109, in wrap_session
    exitstatus=session.exitstatus)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
    return self._docall(self.methods, kwargs)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
    firstresult=self.firstresult).execute()
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 393, in execute
    return wrapped_call(method(*args), self.execute)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 109, in wrapped_call
    wrap_controller.send(call_outcome)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/terminal.py", line 362, in pytest_sessionfinish
    self.config.hook.pytest_terminal_summary(terminalreporter=self)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
    return self._docall(self.methods, kwargs)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
    firstresult=self.firstresult).execute()
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
    res = method(*args)
  File "/home/monkey/ce402c011ae38dae/.tox/py27/local/lib/python2.7/site-packages/pytest_cov/plugin.py", line 164, in pytest_terminal_summary
    assert total is not None, 'Test coverage should never be `None`'
_pytest.assertion.reinterpret.AssertionError: Test coverage should never be `None`
ERROR: InvocationError: '/home/monkey/ce402c011ae38dae/.tox/py27/bin/py.test --teamcity --cov=usersvc --cov-report=html --cov-report=xml --cov-report=annotate'
_________________________________________________________________________________________________________________________________________________________ summary __________________________________________________________________________________________________________________________________________________________
ERROR:   py27: commands failed

As you can see it actually prints a coverage report to stdout, so I don't know why it thinks the test coverage is None.

Here's what's installed:

$ .tox/py27/bin/pip freeze | egrep 'pytest|cov'
You are using pip version 7.1.0, however version 7.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
cov-core==1.15.0
coverage==3.7.1
pytest==2.7.2
pytest-cov==2.0.0
pytest-xdist==1.13.1
@ionelmc
Copy link
Member

ionelmc commented Aug 21, 2015

Interesting. What's your command line and pytest options (specifically addopts)?

@ionelmc
Copy link
Member

ionelmc commented Aug 21, 2015

PS. cov-core is not needed anymore.

@msabramo
Copy link
Contributor Author

It's looking like this might be an interaction between pytest-cov 2.0 and teamcity-messages, because it fails when the py.test command-line includes --teamcity and it seems to be okay without it.

Hmmm... I'll post more as I find out more...

@msabramo
Copy link
Contributor Author

Hmmm, upgrading from teamcity-messages 1.9.4 to 1.14 seems to fix the problem.

Hope this helps someone.

@yoloseem
Copy link

Well. I'm still getting this message on Travis CI with pytest == 2.9.2, pytest-cov == 2.3.0 and pytest-xdist == 1.14. However there was no problem to get a coverage result with CodeCov even it printed erroneous output.

Full messages were like:

(...)
[gw1] PASSED tests/web/util_test.py::test_slc 
[gw0] PASSED tests/web/util_test.py::test_slc_entry INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/main.py", line 94, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/main.py", line 125, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pytest_cov/plugin.py", line 221, in pytest_runtestloop
INTERNALERROR>     assert self.cov_total is not None, 'Test coverage should never be `None`'
INTERNALERROR> AssertionError: Test coverage should never be `None`
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/main.py", line 94, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/main.py", line 125, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pytest_cov/plugin.py", line 221, in pytest_runtestloop
INTERNALERROR>     assert self.cov_total is not None, 'Test coverage should never be `None`'
INTERNALERROR> AssertionError: Test coverage should never be `None`

---------- coverage: platform linux2, python 2.7.9-final-0 -----------
Coverage XML written to file coverage.xml

=================== 1062 passed, 1 skipped in 313.52 seconds ===================
The command "py.test -n2 --durations=20 --database-url 'postgresql:///travis_ci_test?user=postgres' --cov-config .coveragerc --cov-report=xml --cov=beat -vv -x --rerun 5 tests/" exited with 0.

@ionelmc
Copy link
Member

ionelmc commented Jul 11, 2016

@yoloseem what's your coverage version?

@yoloseem
Copy link

@ionelmc Didn't pinned explicitly but 4.1 is installed by coverage>=3.7.1 (from pytest-cov>=2.3.0). Tried again with the latest 4.2b1 but the problem remains.

@ionelmc ionelmc reopened this Jul 11, 2016
@yhager
Copy link

yhager commented Aug 12, 2016

It only happens to me when I specify -n in py.test invocation. Even -n 1 causes it.

platform linux -- Python 3.5.2, pytest-2.9.2, py-1.4.31, pluggy-0.3.1
plugins: cov-2.3.0, xdist-1.14, capturelog-0.7

@ionelmc
Copy link
Member

ionelmc commented Aug 12, 2016

@yhager I'm pretty sure your problem is #124 which is fixed in 2.3.1

@yhager
Copy link

yhager commented Aug 12, 2016

@ionelmc that's correct. I upgraded to 2.3.1 and I can't recreate it. Thx.

@ionelmc ionelmc closed this as completed Mar 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants