@@ -595,14 +595,14 @@ def test_getoption(self, pytester: Pytester) -> None:
595
595
def test_getconftest_pathlist (self , pytester : Pytester , tmp_path : Path ) -> None :
596
596
somepath = tmp_path .joinpath ("x" , "y" , "z" )
597
597
p = tmp_path .joinpath ("conftest.py" )
598
- p .write_text (f"pathlist = ['.', { str (somepath )!r} ]" )
598
+ p .write_text (f"mylist = ['.', { str (somepath )!r} ]" )
599
599
config = pytester .parseconfigure (p )
600
600
assert (
601
601
config ._getconftest_pathlist ("notexist" , path = tmp_path , rootpath = tmp_path )
602
602
is None
603
603
)
604
604
pl = (
605
- config ._getconftest_pathlist ("pathlist " , path = tmp_path , rootpath = tmp_path )
605
+ config ._getconftest_pathlist ("mylist " , path = tmp_path , rootpath = tmp_path )
606
606
or []
607
607
)
608
608
print (pl )
@@ -634,41 +634,37 @@ def pytest_addoption(parser):
634
634
assert val == "hello"
635
635
pytest .raises (ValueError , config .getini , "other" )
636
636
637
- def make_conftest_for_pathlist (self , pytester : Pytester ) -> None :
637
+ @pytest .mark .parametrize ("config_type" , ["ini" , "pyproject" ])
638
+ @pytest .mark .parametrize ("ini_type" , ["paths" , "pathlist" ])
639
+ def test_addini_paths (
640
+ self , pytester : Pytester , config_type : str , ini_type : str
641
+ ) -> None :
638
642
pytester .makeconftest (
639
- """
643
+ f """
640
644
def pytest_addoption(parser):
641
- parser.addini("paths", "my new ini value", type="pathlist ")
645
+ parser.addini("paths", "my new ini value", type="{ ini_type } ")
642
646
parser.addini("abc", "abc value")
643
647
"""
644
648
)
645
-
646
- def test_addini_pathlist_ini_files (self , pytester : Pytester ) -> None :
647
- self .make_conftest_for_pathlist (pytester )
648
- p = pytester .makeini (
649
+ if config_type == "ini" :
650
+ inipath = pytester .makeini (
651
+ """
652
+ [pytest]
653
+ paths=hello world/sub.py
649
654
"""
650
- [pytest]
651
- paths=hello world/sub.py
652
- """
653
- )
654
- self .check_config_pathlist (pytester , p )
655
-
656
- def test_addini_pathlist_pyproject_toml (self , pytester : Pytester ) -> None :
657
- self .make_conftest_for_pathlist (pytester )
658
- p = pytester .makepyprojecttoml (
655
+ )
656
+ elif config_type == "pyproject" :
657
+ inipath = pytester .makepyprojecttoml (
658
+ """
659
+ [tool.pytest.ini_options]
660
+ paths=["hello", "world/sub.py"]
659
661
"""
660
- [tool.pytest.ini_options]
661
- paths=["hello", "world/sub.py"]
662
- """
663
- )
664
- self .check_config_pathlist (pytester , p )
665
-
666
- def check_config_pathlist (self , pytester : Pytester , config_path : Path ) -> None :
662
+ )
667
663
config = pytester .parseconfig ()
668
664
values = config .getini ("paths" )
669
665
assert len (values ) == 2
670
- assert values [0 ] == config_path .parent .joinpath ("hello" )
671
- assert values [1 ] == config_path .parent .joinpath ("world/sub.py" )
666
+ assert values [0 ] == inipath .parent .joinpath ("hello" )
667
+ assert values [1 ] == inipath .parent .joinpath ("world/sub.py" )
672
668
pytest .raises (ValueError , config .getini , "other" )
673
669
674
670
def make_conftest_for_args (self , pytester : Pytester ) -> None :
@@ -1519,24 +1515,29 @@ def test_pass(pytestconfig):
1519
1515
assert result .ret == 0
1520
1516
result .stdout .fnmatch_lines (["custom_option:3.0" ])
1521
1517
1522
- def test_override_ini_pathlist (self , pytester : Pytester ) -> None :
1518
+ @pytest .mark .parametrize ("ini_type" , ["paths" , "pathlist" ])
1519
+ def test_override_ini_paths (self , pytester : Pytester , ini_type : str ) -> None :
1523
1520
pytester .makeconftest (
1524
- """
1521
+ f """
1525
1522
def pytest_addoption(parser):
1526
- parser.addini("paths", "my new ini value", type="pathlist ")"""
1523
+ parser.addini("paths", "my new ini value", type="{ ini_type } ")"""
1527
1524
)
1528
1525
pytester .makeini (
1529
1526
"""
1530
1527
[pytest]
1531
1528
paths=blah.py"""
1532
1529
)
1533
1530
pytester .makepyfile (
1534
- """
1535
- def test_pathlist (pytestconfig):
1531
+ rf """
1532
+ def test_overriden (pytestconfig):
1536
1533
config_paths = pytestconfig.getini("paths")
1537
1534
print(config_paths)
1538
1535
for cpf in config_paths:
1539
- print('\\ nuser_path:%s' % cpf.basename)"""
1536
+ if "{ ini_type } " == "pathlist":
1537
+ print('\nuser_path:%s' % cpf.basename)
1538
+ else:
1539
+ print('\nuser_path:%s' % cpf.name)
1540
+ """
1540
1541
)
1541
1542
result = pytester .runpytest (
1542
1543
"--override-ini" , "paths=foo/bar1.py foo/bar2.py" , "-s"
0 commit comments