|
8 | 8 | import textwrap |
9 | 9 | import types |
10 | 10 |
|
| 11 | +import attr |
11 | 12 | import py |
12 | 13 | import six |
13 | 14 |
|
@@ -108,6 +109,60 @@ def test_option(pytestconfig): |
108 | 109 | assert result.ret == 0 |
109 | 110 | result.stdout.fnmatch_lines(["*1 passed*"]) |
110 | 111 |
|
| 112 | + @pytest.mark.parametrize("load_cov_early", [True, False]) |
| 113 | + def test_early_load_setuptools_name(self, testdir, monkeypatch, load_cov_early): |
| 114 | + pkg_resources = pytest.importorskip("pkg_resources") |
| 115 | + |
| 116 | + testdir.makepyfile(mytestplugin1_module="") |
| 117 | + testdir.makepyfile(mytestplugin2_module="") |
| 118 | + testdir.makepyfile(mycov_module="") |
| 119 | + testdir.syspathinsert() |
| 120 | + |
| 121 | + loaded = [] |
| 122 | + |
| 123 | + @attr.s |
| 124 | + class DummyEntryPoint(object): |
| 125 | + name = attr.ib() |
| 126 | + module = attr.ib() |
| 127 | + version = "1.0" |
| 128 | + |
| 129 | + @property |
| 130 | + def project_name(self): |
| 131 | + return self.name |
| 132 | + |
| 133 | + def load(self): |
| 134 | + __import__(self.module) |
| 135 | + loaded.append(self.name) |
| 136 | + return sys.modules[self.module] |
| 137 | + |
| 138 | + @property |
| 139 | + def dist(self): |
| 140 | + return self |
| 141 | + |
| 142 | + def _get_metadata(self, *args): |
| 143 | + return [] |
| 144 | + |
| 145 | + entry_points = [ |
| 146 | + DummyEntryPoint("myplugin1", "mytestplugin1_module"), |
| 147 | + DummyEntryPoint("myplugin2", "mytestplugin2_module"), |
| 148 | + DummyEntryPoint("mycov", "mycov_module"), |
| 149 | + ] |
| 150 | + |
| 151 | + def my_iter(group, name=None): |
| 152 | + assert group == "pytest11" |
| 153 | + for ep in entry_points: |
| 154 | + if name is not None and ep.name != name: |
| 155 | + continue |
| 156 | + yield ep |
| 157 | + |
| 158 | + monkeypatch.setattr(pkg_resources, "iter_entry_points", my_iter) |
| 159 | + params = ("-p", "mycov") if load_cov_early else () |
| 160 | + testdir.runpytest_inprocess(*params) |
| 161 | + if load_cov_early: |
| 162 | + assert loaded == ["mycov", "myplugin1", "myplugin2"] |
| 163 | + else: |
| 164 | + assert loaded == ["myplugin1", "myplugin2", "mycov"] |
| 165 | + |
111 | 166 | def test_assertion_magic(self, testdir): |
112 | 167 | p = testdir.makepyfile( |
113 | 168 | """ |
|
0 commit comments