Skip to content

Commit be7b02c

Browse files
committed
Make test_missing_required_plugins xdist-independent
Also cleaned up the parametrized list using `pytest.param` to assign ids and removed some redundant cases. Follow up to pytest-dev#7459
1 parent 0a0c14d commit be7b02c

File tree

1 file changed

+90
-81
lines changed

1 file changed

+90
-81
lines changed

testing/test_config.py

Lines changed: 90 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import List
77
from typing import Sequence
88

9+
import attr
910
import py.path
1011

1112
import _pytest._code
@@ -250,107 +251,115 @@ def pytest_addoption(parser):
250251
@pytest.mark.parametrize(
251252
"ini_file_text, exception_text",
252253
[
253-
(
254-
"""
255-
[pytest]
256-
required_plugins = fakePlugin1 fakePlugin2
257-
""",
258-
"Missing required plugins: fakePlugin1, fakePlugin2",
259-
),
260-
(
254+
pytest.param(
261255
"""
262-
[pytest]
263-
required_plugins = a pytest-xdist z
264-
""",
256+
[pytest]
257+
required_plugins = a z
258+
""",
265259
"Missing required plugins: a, z",
260+
id="2-missing",
266261
),
267-
(
268-
"""
269-
[pytest]
270-
required_plugins = a q j b c z
271-
""",
272-
"Missing required plugins: a, b, c, j, q, z",
273-
),
274-
(
275-
"""
276-
[pytest]
277-
required_plugins = pytest-xdist
278-
""",
279-
"",
280-
),
281-
(
282-
"""
283-
[pytest]
284-
required_plugins = pytest-xdist==1.32.0
285-
""",
286-
"",
287-
),
288-
(
289-
"""
290-
[pytest]
291-
required_plugins = pytest-xdist>1.0.0,<2.0.0
292-
""",
293-
"",
294-
),
295-
(
262+
pytest.param(
296263
"""
297-
[pytest]
298-
required_plugins = pytest-xdist~=1.32.0 pytest-xdist==1.32.0 pytest-xdist!=0.0.1 pytest-xdist<=99.99.0
299-
pytest-xdist>=1.32.0 pytest-xdist<9.9.9 pytest-xdist>1.30.0 pytest-xdist===1.32.0
300-
""",
301-
"",
264+
[pytest]
265+
required_plugins = a z myplugin
266+
""",
267+
"Missing required plugins: a, z",
268+
id="2-missing-1-ok",
302269
),
303-
(
270+
pytest.param(
304271
"""
305-
[pytest]
306-
required_plugins = pytest-xdist>9.9.9 pytest-xdist==1.32.0 pytest-xdist==8.8.8
307-
""",
308-
"Missing required plugins: pytest-xdist==8.8.8, pytest-xdist>9.9.9",
272+
[pytest]
273+
required_plugins = myplugin
274+
""",
275+
None,
276+
id="1-ok",
309277
),
310-
(
278+
pytest.param(
311279
"""
312-
[pytest]
313-
required_plugins = pytest-xdist==aegsrgrsgs pytest-xdist==-1 pytest-xdist>2.1.1,>3.0.0
314-
""",
315-
"Missing required plugins: pytest-xdist==-1, pytest-xdist==aegsrgrsgs, pytest-xdist>2.1.1,>3.0.0",
280+
[pytest]
281+
required_plugins = myplugin==1.5
282+
""",
283+
None,
284+
id="1-ok-pin-exact",
316285
),
317-
(
286+
pytest.param(
318287
"""
319-
[pytest]
320-
required_plugins = pytest-xdist== pytest-xdist<=
321-
""",
322-
"Missing required plugins: pytest-xdist<=, pytest-xdist==",
288+
[pytest]
289+
required_plugins = myplugin>1.0,<2.0
290+
""",
291+
None,
292+
id="1-ok-pin-loose",
323293
),
324-
(
294+
pytest.param(
325295
"""
326-
[pytest]
327-
required_plugins = pytest-xdist= pytest-xdist<
328-
""",
329-
"Missing required plugins: pytest-xdist<, pytest-xdist=",
296+
[pytest]
297+
required_plugins = pyplugin==1.6
298+
""",
299+
"Missing required plugins: pyplugin==1.6",
300+
id="missing-version",
330301
),
331-
(
302+
pytest.param(
332303
"""
333-
[some_other_header]
334-
required_plugins = wont be triggered
335-
[pytest]
336-
minversion = 5.0.0
337-
""",
338-
"",
304+
[pytest]
305+
required_plugins = pyplugin==1.6 other==1.0
306+
""",
307+
"Missing required plugins: other==1.0, pyplugin==1.6",
308+
id="missing-versions",
339309
),
340-
(
310+
pytest.param(
341311
"""
342-
[pytest]
343-
minversion = 5.0.0
344-
""",
345-
"",
312+
[some_other_header]
313+
required_plugins = wont be triggered
314+
[pytest]
315+
""",
316+
None,
317+
id="invalid-header",
346318
),
347319
],
348320
)
349-
def test_missing_required_plugins(self, testdir, ini_file_text, exception_text):
350-
pytest.importorskip("xdist")
321+
def test_missing_required_plugins(
322+
self, testdir, monkeypatch, ini_file_text, exception_text
323+
):
324+
"""Check 'required_plugins' option with various settings.
351325
352-
testdir.tmpdir.join("pytest.ini").write(textwrap.dedent(ini_file_text))
353-
testdir.monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
326+
This test installs a mock "myplugin-1.5" which is used in the parametrized test cases.
327+
"""
328+
329+
@attr.s
330+
class DummyEntryPoint:
331+
name = attr.ib()
332+
module = attr.ib()
333+
group = "pytest11"
334+
335+
def load(self):
336+
__import__(self.module)
337+
return sys.modules[self.module]
338+
339+
entry_points = [
340+
DummyEntryPoint("myplugin1", "myplugin1_module"),
341+
]
342+
343+
@attr.s
344+
class DummyDist:
345+
entry_points = attr.ib()
346+
files = ()
347+
version = "1.5"
348+
349+
@property
350+
def metadata(self):
351+
return {"name": "myplugin"}
352+
353+
def my_dists():
354+
return [DummyDist(entry_points)]
355+
356+
testdir.makepyfile(myplugin1_module="# my plugin module")
357+
testdir.syspathinsert()
358+
359+
monkeypatch.setattr(importlib_metadata, "distributions", my_dists)
360+
testdir.monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False)
361+
362+
testdir.makeini(ini_file_text)
354363

355364
if exception_text:
356365
with pytest.raises(pytest.fail.Exception, match=exception_text):

0 commit comments

Comments
 (0)