diff --git a/src/pytest_cov/__init__.py b/src/pytest_cov/__init__.py index 82ce08b..87a5412 100644 --- a/src/pytest_cov/__init__.py +++ b/src/pytest_cov/__init__.py @@ -1,3 +1,47 @@ """pytest-cov: avoid already-imported warning: PYTEST_DONT_REWRITE.""" __version__ = '5.0.0' + +import pytest + + +class CoverageError(Exception): + """Indicates that our coverage is too low""" + + +class PytestCovWarning(pytest.PytestWarning): + """ + The base for all pytest-cov warnings, never raised directly. + """ + + +class CovDisabledWarning(PytestCovWarning): + """ + Indicates that Coverage was manually disabled. + """ + + +class CovReportWarning(PytestCovWarning): + """ + Indicates that we failed to generate a report. + """ + + +class CovFailUnderWarning(PytestCovWarning): + """ + Indicates that we failed to generate a report. + """ + + +class CentralCovContextWarning(PytestCovWarning): + """ + Indicates that dynamic_context was set to test_function instead of using the builtin --cov-context. + """ + + +class DistCovError(Exception): + """ + Raised when dynamic_context is set to test_function and xdist is also used. + + See: https://github.com/pytest-dev/pytest-cov/issues/604 + """ diff --git a/src/pytest_cov/engine.py b/src/pytest_cov/engine.py index 73e2f8d..650dbcc 100644 --- a/src/pytest_cov/engine.py +++ b/src/pytest_cov/engine.py @@ -15,8 +15,9 @@ from coverage.data import CoverageData from coverage.sqldata import filename_suffix +from . import CentralCovContextWarning +from . import DistCovError from .embed import cleanup -from .plugin import PytestCovWarning class BrokenCovConfigError(Exception): @@ -231,10 +232,6 @@ def summary(self, stream): return total -class CentralCovContextWarning(PytestCovWarning): - pass - - class Central(CovController): """Implementation for centralised operation.""" @@ -286,10 +283,6 @@ def finish(self): self.node_descs.add(node_desc) -class DistCovError(Exception): - pass - - class DistMaster(CovController): """Implementation for distributed master.""" diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index f0835af..b2b103f 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -11,32 +11,13 @@ from coverage.results import display_covered from coverage.results import should_fail_under +from . import CovDisabledWarning +from . import CovFailUnderWarning +from . import CovReportWarning from . import compat from . import embed -class CoverageError(Exception): - """Indicates that our coverage is too low""" - - -class PytestCovWarning(pytest.PytestWarning): - """ - The base for all pytest-cov warnings, never raised directly - """ - - -class CovDisabledWarning(PytestCovWarning): - """Indicates that Coverage was manually disabled""" - - -class CovReportWarning(PytestCovWarning): - """Indicates that we failed to generate a report""" - - -class CovFailUnderWarning(PytestCovWarning): - """Indicates that we failed to generate a report""" - - def validate_report(arg): file_choices = ['annotate', 'html', 'xml', 'json', 'lcov'] term_choices = ['term', 'term-missing'] diff --git a/tests/test_pytest_cov.py b/tests/test_pytest_cov.py index 2c9d426..72f7ab1 100644 --- a/tests/test_pytest_cov.py +++ b/tests/test_pytest_cov.py @@ -1674,7 +1674,7 @@ def test_dynamic_context(pytester, testdir, opts, prop): """) result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script, *opts.split() + prop.args) if opts: - result.stderr.fnmatch_lines(['pytest_cov.engine.DistCovError: Detected dynamic_context=test_function*']) + result.stderr.fnmatch_lines(['pytest_cov.DistCovError: Detected dynamic_context=test_function*']) else: result.stdout.fnmatch_lines( [