From b9c99e7d50f28666ef8a055bf253694cc91bbc0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ionel=20Cristian=20M=C4=83rie=C8=99?= <contact@ionelmc.ro>
Date: Wed, 18 Sep 2024 02:06:23 +0300
Subject: [PATCH] Add example test with coverage plugin. Ref #642.

---
 tests/test_pytest_cov.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tests/test_pytest_cov.py b/tests/test_pytest_cov.py
index 0969267a..5d7b3be4 100644
--- a/tests/test_pytest_cov.py
+++ b/tests/test_pytest_cov.py
@@ -1631,6 +1631,34 @@ 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_do_not_append_coverage(pytester, testdir, opts, prop):
     script = testdir.makepyfile(test_1=prop.code)