Skip to content

Commit 76fe2a7

Browse files
committed
Move the warnings/errors in a place that doesn't import anything.
1 parent a9ea7b7 commit 76fe2a7

File tree

4 files changed

+50
-32
lines changed

4 files changed

+50
-32
lines changed

src/pytest_cov/__init__.py

+44
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
11
"""pytest-cov: avoid already-imported warning: PYTEST_DONT_REWRITE."""
22

33
__version__ = '5.0.0'
4+
5+
import pytest
6+
7+
8+
class CoverageError(Exception):
9+
"""Indicates that our coverage is too low"""
10+
11+
12+
class PytestCovWarning(pytest.PytestWarning):
13+
"""
14+
The base for all pytest-cov warnings, never raised directly.
15+
"""
16+
17+
18+
class CovDisabledWarning(PytestCovWarning):
19+
"""
20+
Indicates that Coverage was manually disabled.
21+
"""
22+
23+
24+
class CovReportWarning(PytestCovWarning):
25+
"""
26+
Indicates that we failed to generate a report.
27+
"""
28+
29+
30+
class CovFailUnderWarning(PytestCovWarning):
31+
"""
32+
Indicates that we failed to generate a report.
33+
"""
34+
35+
36+
class CentralCovContextWarning(PytestCovWarning):
37+
"""
38+
Indicates that dynamic_context was set to test_function instead of using the builtin --cov-context.
39+
"""
40+
41+
42+
class DistCovError(Exception):
43+
"""
44+
Raised when dynamic_context is set to test_function and xdist is also used.
45+
46+
See: https://github.com/pytest-dev/pytest-cov/issues/604
47+
"""

src/pytest_cov/engine.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
from coverage.data import CoverageData
1616
from coverage.sqldata import filename_suffix
1717

18+
from . import CentralCovContextWarning
19+
from . import DistCovError
1820
from .embed import cleanup
19-
from .plugin import PytestCovWarning
2021

2122

2223
class BrokenCovConfigError(Exception):
@@ -231,10 +232,6 @@ def summary(self, stream):
231232
return total
232233

233234

234-
class CentralCovContextWarning(PytestCovWarning):
235-
pass
236-
237-
238235
class Central(CovController):
239236
"""Implementation for centralised operation."""
240237

@@ -286,10 +283,6 @@ def finish(self):
286283
self.node_descs.add(node_desc)
287284

288285

289-
class DistCovError(Exception):
290-
pass
291-
292-
293286
class DistMaster(CovController):
294287
"""Implementation for distributed master."""
295288

src/pytest_cov/plugin.py

+3-22
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,13 @@
1111
from coverage.results import display_covered
1212
from coverage.results import should_fail_under
1313

14+
from . import CovDisabledWarning
15+
from . import CovFailUnderWarning
16+
from . import CovReportWarning
1417
from . import compat
1518
from . import embed
1619

1720

18-
class CoverageError(Exception):
19-
"""Indicates that our coverage is too low"""
20-
21-
22-
class PytestCovWarning(pytest.PytestWarning):
23-
"""
24-
The base for all pytest-cov warnings, never raised directly
25-
"""
26-
27-
28-
class CovDisabledWarning(PytestCovWarning):
29-
"""Indicates that Coverage was manually disabled"""
30-
31-
32-
class CovReportWarning(PytestCovWarning):
33-
"""Indicates that we failed to generate a report"""
34-
35-
36-
class CovFailUnderWarning(PytestCovWarning):
37-
"""Indicates that we failed to generate a report"""
38-
39-
4021
def validate_report(arg):
4122
file_choices = ['annotate', 'html', 'xml', 'json', 'lcov']
4223
term_choices = ['term', 'term-missing']

tests/test_pytest_cov.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ def test_dynamic_context(pytester, testdir, opts, prop):
16741674
""")
16751675
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script, *opts.split() + prop.args)
16761676
if opts:
1677-
result.stderr.fnmatch_lines(['pytest_cov.engine.DistCovError: Detected dynamic_context=test_function*'])
1677+
result.stderr.fnmatch_lines(['pytest_cov.DistCovError: Detected dynamic_context=test_function*'])
16781678
else:
16791679
result.stdout.fnmatch_lines(
16801680
[

0 commit comments

Comments
 (0)