Skip to content

Commit 0c8a54a

Browse files
authored
Merge pull request #9310 from bluetech/test-main-same-mod
testing/test_session: add a regression test for an old bug
2 parents c7be96d + 43213ad commit 0c8a54a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

testing/test_session.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,54 @@ def pytest_sessionfinish():
335335
assert res.ret == ExitCode.NO_TESTS_COLLECTED
336336

337337

338+
def test_collection_args_do_not_duplicate_modules(pytester: Pytester) -> None:
339+
"""Test that when multiple collection args are specified on the command line
340+
for the same module, only a single Module collector is created.
341+
342+
Regression test for #723, #3358.
343+
"""
344+
pytester.makepyfile(
345+
**{
346+
"d/test_it": """
347+
def test_1(): pass
348+
def test_2(): pass
349+
"""
350+
}
351+
)
352+
353+
result = pytester.runpytest(
354+
"--collect-only",
355+
"d/test_it.py::test_1",
356+
"d/test_it.py::test_2",
357+
)
358+
result.stdout.fnmatch_lines(
359+
[
360+
"<Module d/test_it.py>",
361+
" <Function test_1>",
362+
" <Function test_2>",
363+
],
364+
consecutive=True,
365+
)
366+
367+
# Different, but related case.
368+
result = pytester.runpytest(
369+
"--collect-only",
370+
"--keep-duplicates",
371+
"d",
372+
"d",
373+
)
374+
result.stdout.fnmatch_lines(
375+
[
376+
"<Module d/test_it.py>",
377+
" <Function test_1>",
378+
" <Function test_2>",
379+
" <Function test_1>",
380+
" <Function test_2>",
381+
],
382+
consecutive=True,
383+
)
384+
385+
338386
@pytest.mark.parametrize("path", ["root", "{relative}/root", "{environment}/root"])
339387
def test_rootdir_option_arg(
340388
pytester: Pytester, monkeypatch: MonkeyPatch, path: str

0 commit comments

Comments
 (0)