Skip to content

Commit

Permalink
Add reproducer for weird xdist dynamic_context interaction. Ref #604.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Sep 17, 2024
1 parent 310feb0 commit 6fa6109
Showing 1 changed file with 68 additions and 3 deletions.
71 changes: 68 additions & 3 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def test_bar():
"""


COVERAGERC_SOURCE = """\
[run]
source = .
Expand Down Expand Up @@ -153,8 +152,13 @@ def test_foo(cov):

xdist_params = pytest.mark.parametrize(
'opts',
['', pytest.param('-n 1', marks=pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"'))],
ids=['nodist', 'xdist'],
[
'',
pytest.param('-n 1', marks=pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')),
pytest.param('-n 2', marks=pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')),
pytest.param('-n 3', marks=pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')),
],
ids=['nodist', '1xdist', '2xdist', '3xdist'],
)


Expand Down Expand Up @@ -1631,6 +1635,67 @@ def test_append_coverage(pytester, testdir, opts, prop):
)


@xdist_params
def test_coverage_plugin(pytester, testdir, opts, prop):
script = testdir.makepyfile(test_1=prop.code)
testdir.makepyfile(
coverageplugin="""
import coverage
class ExamplePlugin(coverage.CoveragePlugin):
pass
def coverage_init(reg, options):
reg.add_file_tracer(ExamplePlugin())
"""
)
testdir.makepyprojecttoml(f"""
[tool.coverage.run]
plugins = ["coverageplugin"]
concurrency = ["thread", "multiprocessing"]
{prop.conf}
""")
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script, *opts.split() + prop.args)
result.stdout.fnmatch_lines(
[
f'test_1* {prop.result}*',
]
)


@xdist_params
def test_dynamic_context(pytester, testdir, opts, prop):
script = testdir.makepyfile(test_1=prop.code)
testdir.makepyprojecttoml(f"""
[tool.coverage.run]
dynamic_context = "test_function"
parallel = true
{prop.conf}
""")
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script, *opts.split() + prop.args)
result.stdout.fnmatch_lines(
[
f'test_1* {prop.result}*',
]
)


@xdist_params
def test_simple(pytester, testdir, opts, prop):
script = testdir.makepyfile(test_1=prop.code)
testdir.makepyprojecttoml(f"""
[tool.coverage.run]
parallel = true
{prop.conf}
""")
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script, *opts.split() + prop.args)
result.stdout.fnmatch_lines(
[
f'test_1* {prop.result}*',
]
)


@xdist_params
def test_do_not_append_coverage(pytester, testdir, opts, prop):
script = testdir.makepyfile(test_1=prop.code)
Expand Down

0 comments on commit 6fa6109

Please sign in to comment.