question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pytest gives "Coverage disabled via --no-cov switch!" warning even --no-cov is not given!!

See original GitHub issue
  • a detailed description of the bug or suggestion I have not set --no-cov in any cli or configs, but it is given me the warning “Coverage disabled via --no-cov switch!”. Even worse, I have enabled coverage in pytest.ini:
[pytest]
addopts = --cov=mypackage -vvv -s

But coverage is not running!

Here is output:

(ENV) $ python -m pytest
=================================================== test session starts ====================================================
platform darwin -- Python 2.7.15, pytest-4.4.1, py-1.8.0, pluggy-0.9.0 -- /Users/local/myrepo_new/ENV/bin/python
cachedir: .pytest_cache
rootdir: /Users/local/myrepo_new, inifile: pytest.ini
plugins: cov-2.6.1
collected 1 item                                                                                                           

test/test_myrepo.py::test_x PASSED
WARNING: Coverage disabled via --no-cov switch!

===================================================== warnings summary =====================================================
ENV/lib/python2.7/site-packages/pytest_cov/plugin.py:253
  /Users/local/myrepo_new/ENV/lib/python2.7/site-packages/pytest_cov/plugin.py:253: PytestWarning: Coverage disabled via --no-cov switch!
    warnings.warn(pytest.PytestWarning(message))

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=========================================== 1 passed, 1 warnings in 0.03 seconds ===========================================
  • output of pip list from the virtual environment you are using
(ENV)$ pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Package        Version
-------------- -------
atomicwrites   1.3.0  
attrs          19.1.0 
coverage       4.5.3  
funcsigs       1.0.2  
more-itertools 5.0.0  
pathlib2       2.3.3  
pip            19.1   
pluggy         0.9.0  
py             1.8.0  
pytest         4.4.1  
pytest-cov     2.6.1  
scandir        1.10.0 
setuptools     41.0.1 
six            1.12.0 
wheel          0.33.1 
  • pytest and operating system versions
(ENV) $ pytest --version
This is pytest version 4.4.1, imported from /Users/local/myrepo_new/ENV/lib/python2.7/site-packages/pytest.pyc
setuptools registered plugins:
  pytest-cov-2.6.1 at /Users/local/myrepo_new/ENV/lib/python2.7/site-packages/pytest_cov/plugin.py
(ENV)$ plutil -p /System/Library/CoreServices/SystemVersion.plist
{
  "iOSSupportVersion" => "12.0"
  "ProductBuildVersion" => "18D25"
  "ProductCopyright" => "1983-2018 Apple Inc."
  "ProductName" => "Mac OS X"
  "ProductUserVisibleVersion" => "10.14.3"
  "ProductVersion" => "10.14.3"
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

6reactions
ssbarneacommented, Jun 24, 2019

Presence of --no-cov switch should just silence the warning because that is the only way a developer can disable coverage on project having them without altering the codebase. The project itself may have pycov parameters mentioned in its tox.ini or pytest.ini files but once the use defines PYTEST_ADDOPTS, this will take precedence over other options.

I hope that this explains the reasoning behind silencing the warning, as it is just noise. Maybe another approach would be to make a a DEBUG level message, so it will not appear on normal executions.

3reactions
ssbarneacommented, Jun 19, 2019

I am facing the same annoying warning when I have PYTEST_ADDOPTS='-s --maxfail=10 --no-cov' and when running pytest, I get 7 extra lines of warnings which are useless. If user mentions that he does not want coverage, there is no reason to throw any warnings.

WARNING: Coverage disabled via --no-cov switch!
================================================================================= warnings summary ==================================================================================
/Users/ssbarnea/.pyenv/versions/3.6.8/lib/python3.6/site-packages/pytest_cov/plugin.py:253
  /Users/ssbarnea/.pyenv/versions/3.6.8/lib/python3.6/site-packages/pytest_cov/plugin.py:253: PytestWarning: Coverage disabled via --no-cov switch!
    warnings.warn(pytest.PytestWarning(message))

-- Docs: https://docs.pytest.org/en/latest/warnings.html

Environment should just take precedence over values configured in pytest.ini.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pytest --nocov throws warnings in pycharm - JetBrains YouTrack
I need to have the test coverage configured for the CI system. One cannot set breakpoints if the pytest coverage is on, though....
Read more >
Module sample.py was never imported - Stack Overflow
Anyone has an idea why coverage.py does not work? hence, if I run coverage run -m py.test test.py separately, it does not show...
Read more >
pytest-cov - PyPI
Pytest plugin for measuring coverage. ... support: you can use all of pytest-xdist's features and still get coverage. ... Improved the --no-cov warning....
Read more >
Skipping selected test coverage warnings with undercover
Skipping selected test coverage warnings with undercover. Undercover checks are all about making sure that no changed line of code is merged ...
Read more >
pytest-benchmark - Read the Docs
Will run the test function up to num- ber of times in the calibration phase. See –benchmark-warmup- iterations. Note: Even the warmup phase ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found