From c87e54643ef696ed2b0e2b9a4209581da8467fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionel=20Cristian=20M=C4=83rie=C8=99?= Date: Wed, 18 Sep 2024 02:19:35 +0300 Subject: [PATCH] Add reproducer for weird xdist dynamic_context interaction. Ref #604. --- tests/test_pytest_cov.py | 71 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/tests/test_pytest_cov.py b/tests/test_pytest_cov.py index 0969267a..9f064972 100644 --- a/tests/test_pytest_cov.py +++ b/tests/test_pytest_cov.py @@ -48,7 +48,6 @@ def test_bar(): """ - COVERAGERC_SOURCE = """\ [run] source = . @@ -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'], ) @@ -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)