Skip to content

Commit c87e546

Browse files
committed
Add reproducer for weird xdist dynamic_context interaction. Ref #604.
1 parent 310feb0 commit c87e546

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

tests/test_pytest_cov.py

+68-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def test_bar():
4848
4949
"""
5050

51-
5251
COVERAGERC_SOURCE = """\
5352
[run]
5453
source = .
@@ -153,8 +152,13 @@ def test_foo(cov):
153152

154153
xdist_params = pytest.mark.parametrize(
155154
'opts',
156-
['', pytest.param('-n 1', marks=pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"'))],
157-
ids=['nodist', 'xdist'],
155+
[
156+
'',
157+
pytest.param('-n 1', marks=pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')),
158+
pytest.param('-n 2', marks=pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')),
159+
pytest.param('-n 3', marks=pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')),
160+
],
161+
ids=['nodist', '1xdist', '2xdist', '3xdist'],
158162
)
159163

160164

@@ -1631,6 +1635,67 @@ def test_append_coverage(pytester, testdir, opts, prop):
16311635
)
16321636

16331637

1638+
@xdist_params
1639+
def test_coverage_plugin(pytester, testdir, opts, prop):
1640+
script = testdir.makepyfile(test_1=prop.code)
1641+
testdir.makepyfile(
1642+
coverageplugin="""
1643+
import coverage
1644+
1645+
class ExamplePlugin(coverage.CoveragePlugin):
1646+
pass
1647+
1648+
def coverage_init(reg, options):
1649+
reg.add_file_tracer(ExamplePlugin())
1650+
"""
1651+
)
1652+
testdir.makepyprojecttoml(f"""
1653+
[tool.coverage.run]
1654+
plugins = ["coverageplugin"]
1655+
concurrency = ["thread", "multiprocessing"]
1656+
{prop.conf}
1657+
""")
1658+
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script, *opts.split() + prop.args)
1659+
result.stdout.fnmatch_lines(
1660+
[
1661+
f'test_1* {prop.result}*',
1662+
]
1663+
)
1664+
1665+
1666+
@xdist_params
1667+
def test_dynamic_context(pytester, testdir, opts, prop):
1668+
script = testdir.makepyfile(test_1=prop.code)
1669+
testdir.makepyprojecttoml(f"""
1670+
[tool.coverage.run]
1671+
dynamic_context = "test_function"
1672+
parallel = true
1673+
{prop.conf}
1674+
""")
1675+
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script, *opts.split() + prop.args)
1676+
result.stdout.fnmatch_lines(
1677+
[
1678+
f'test_1* {prop.result}*',
1679+
]
1680+
)
1681+
1682+
1683+
@xdist_params
1684+
def test_simple(pytester, testdir, opts, prop):
1685+
script = testdir.makepyfile(test_1=prop.code)
1686+
testdir.makepyprojecttoml(f"""
1687+
[tool.coverage.run]
1688+
parallel = true
1689+
{prop.conf}
1690+
""")
1691+
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script, *opts.split() + prop.args)
1692+
result.stdout.fnmatch_lines(
1693+
[
1694+
f'test_1* {prop.result}*',
1695+
]
1696+
)
1697+
1698+
16341699
@xdist_params
16351700
def test_do_not_append_coverage(pytester, testdir, opts, prop):
16361701
script = testdir.makepyfile(test_1=prop.code)

0 commit comments

Comments
 (0)