File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ Charles Machalow
8989Charles-Meldhine Madi Mnemoi (cmnemoi)
9090Charnjit SiNGH (CCSJ)
9191Cheuk Ting Ho
92+ Chris Burr
9293Chris Mahoney
9394Chris Lamb
9495Chris NeJame
Original file line number Diff line number Diff line change 1+ Fixed a regression in pytest 9.1.0 where ``conftest.py `` files located in ``<invocation dir>/test* `` were no longer loaded as initial conftests when invoked without arguments.
2+ This could cause certain hooks (like :hook: `pytest_addoption `) in these files to not fire.
Original file line number Diff line number Diff line change @@ -645,18 +645,18 @@ def _set_initial_conftests(
645645 if i != - 1 :
646646 path = path [:i ]
647647 anchor = absolutepath (invocation_dir / path )
648-
649648 # Ensure we do not break if what appears to be an anchor
650649 # is in fact a very long option (#10169, #11394).
651- if safe_exists (anchor ):
652- anchors . append ( anchor )
653- # Let's also consider test* subdirs.
654- if anchor . is_dir ():
655- for x in anchor . glob ( " test*" ):
656- if x .is_dir ():
657- anchors . append ( x )
650+ if not safe_exists (anchor ):
651+ continue
652+
653+ anchors . append ( anchor )
654+ # Let's also consider test* subdirs.
655+ if anchor .is_dir ():
656+ anchors . extend ( x for x in anchor . glob ( "test*" ) if x . is_dir () )
658657 if not anchors :
659- anchors = [invocation_dir ]
658+ anchors .append (invocation_dir )
659+ anchors .extend (x for x in invocation_dir .glob ("test*" ) if x .is_dir ())
660660
661661 for anchor in anchors :
662662 self ._loadconftestmodules (
Original file line number Diff line number Diff line change @@ -440,6 +440,28 @@ def pytest_addoption(parser):
440440 result .stdout .fnmatch_lines (["*--xyz*" ])
441441
442442
443+ def test_conftests_in_invocation_dir_tests_is_initial (pytester : Pytester ) -> None :
444+ """An option registered in a conftest under ``test*`` subdir of the
445+ invocation dir is loaded as initial when no command-line arguments
446+ or `testpaths` are given (#14608).
447+ """
448+ pytester .makepyfile (
449+ ** {
450+ "tests/conftest.py" : """
451+ def pytest_addoption(parser):
452+ parser.addoption("--db-url")
453+ """ ,
454+ "test_it.py" : """
455+ def test_it(request):
456+ assert request.config.getoption("--db-url") == "scheme://host/db"
457+ """ ,
458+ }
459+ )
460+ result = pytester .runpytest ("--db-url" , "scheme://host/db" )
461+ assert result .ret == ExitCode .OK
462+ result .assert_outcomes (passed = 1 )
463+
464+
443465def test_conftest_import_order (pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
444466 ct1 = pytester .makeconftest ("" )
445467 sub = pytester .mkdir ("sub" )
You can’t perform that action at this time.
0 commit comments