@@ -1673,12 +1673,21 @@ def venv_world_fixture(tmp_path_factory):
1673
1673
# Create a virtualenv.
1674
1674
run_command ("python -m virtualenv venv" )
1675
1675
1676
- # A third-party package that installs two different packages.
1676
+ # A third-party package that installs a few different packages.
1677
1677
make_file ("third_pkg/third/__init__.py" , """\
1678
1678
import fourth
1679
1679
def third(x):
1680
1680
return 3 * x
1681
1681
""" )
1682
+ # Use plugin2.py as third.plugin
1683
+ with open (os .path .join (os .path .dirname (__file__ ), "plugin2.py" )) as f :
1684
+ make_file ("third_pkg/third/plugin.py" , f .read ())
1685
+ # A render function for plugin2 to use for dynamic file names.
1686
+ make_file ("third_pkg/third/render.py" , """\
1687
+ def render(filename, linenum):
1688
+ return "HTML: {}@{}".format(filename, linenum)
1689
+ """ )
1690
+ # Another package that third can use.
1682
1691
make_file ("third_pkg/fourth/__init__.py" , """\
1683
1692
def fourth(x):
1684
1693
return 4 * x
@@ -1805,3 +1814,20 @@ def test_venv_isnt_measured(self, coverage_command):
1805
1814
assert "third" not in out
1806
1815
assert "coverage" not in out
1807
1816
assert "colorsys" not in out
1817
+
1818
+ @pytest .mark .skipif (not env .C_TRACER , reason = "Plugins are only supported with the C tracer." )
1819
+ def test_venv_with_dynamic_plugin (self , coverage_command ):
1820
+ # https://github.com/nedbat/coveragepy/issues/1150
1821
+ # Django coverage plugin was incorrectly getting warnings:
1822
+ # "Already imported: ... django/template/blah.py"
1823
+ # It happened because coverage imported the plugin, which imported
1824
+ # Django, and then the Django files were reported as traceable.
1825
+ self .make_file (".coveragerc" , "[run]\n plugins=third.plugin\n " )
1826
+ self .make_file ("myrender.py" , """\
1827
+ import third.render
1828
+ print(third.render.render("hello.html", 1723))
1829
+ """ )
1830
+ out = run_in_venv (coverage_command + " run --source=. myrender.py" )
1831
+ # The output should not have this warning:
1832
+ # Already imported a file that will be measured: ...third/render.py (already-imported)
1833
+ assert out == "HTML: hello.html@1723\n "
0 commit comments