49
49
from _pytest ._io import TerminalWriter
50
50
from _pytest .compat import final
51
51
from _pytest .compat import importlib_metadata
52
- from _pytest .compat import LEGACY_PATH
53
- from _pytest .compat import legacy_path
54
52
from _pytest .outcomes import fail
55
53
from _pytest .outcomes import Skipped
56
54
from _pytest .pathlib import absolutepath
@@ -240,6 +238,7 @@ def directory_arg(path: str, optname: str) -> str:
240
238
"unittest" ,
241
239
"capture" ,
242
240
"skipping" ,
241
+ "legacypath" ,
243
242
"tmpdir" ,
244
243
"monkeypatch" ,
245
244
"recwarn" ,
@@ -949,17 +948,6 @@ def __init__(
949
948
950
949
self .cache : Optional [Cache ] = None
951
950
952
- @property
953
- def invocation_dir (self ) -> LEGACY_PATH :
954
- """The directory from which pytest was invoked.
955
-
956
- Prefer to use :attr:`invocation_params.dir <InvocationParams.dir>`,
957
- which is a :class:`pathlib.Path`.
958
-
959
- :type: LEGACY_PATH
960
- """
961
- return legacy_path (str (self .invocation_params .dir ))
962
-
963
951
@property
964
952
def rootpath (self ) -> Path :
965
953
"""The path to the :ref:`rootdir <rootdir>`.
@@ -970,16 +958,6 @@ def rootpath(self) -> Path:
970
958
"""
971
959
return self ._rootpath
972
960
973
- @property
974
- def rootdir (self ) -> LEGACY_PATH :
975
- """The path to the :ref:`rootdir <rootdir>`.
976
-
977
- Prefer to use :attr:`rootpath`, which is a :class:`pathlib.Path`.
978
-
979
- :type: LEGACY_PATH
980
- """
981
- return legacy_path (str (self .rootpath ))
982
-
983
961
@property
984
962
def inipath (self ) -> Optional [Path ]:
985
963
"""The path to the :ref:`configfile <configfiles>`.
@@ -990,16 +968,6 @@ def inipath(self) -> Optional[Path]:
990
968
"""
991
969
return self ._inipath
992
970
993
- @property
994
- def inifile (self ) -> Optional [LEGACY_PATH ]:
995
- """The path to the :ref:`configfile <configfiles>`.
996
-
997
- Prefer to use :attr:`inipath`, which is a :class:`pathlib.Path`.
998
-
999
- :type: Optional[LEGACY_PATH]
1000
- """
1001
- return legacy_path (str (self .inipath )) if self .inipath else None
1002
-
1003
971
def add_cleanup (self , func : Callable [[], None ]) -> None :
1004
972
"""Add a function to be called when the config object gets out of
1005
973
use (usually coninciding with pytest_unconfigure)."""
@@ -1400,6 +1368,12 @@ def getini(self, name: str):
1400
1368
self ._inicache [name ] = val = self ._getini (name )
1401
1369
return val
1402
1370
1371
+ # Meant for easy monkeypatching by legacypath plugin.
1372
+ # Can be inlined back (with no cover removed) once legacypath is gone.
1373
+ def _getini_unknown_type (self , name : str , type : str , value : Union [str , List [str ]]):
1374
+ msg = f"unknown configuration type: { type } "
1375
+ raise ValueError (msg , value ) # pragma: no cover
1376
+
1403
1377
def _getini (self , name : str ):
1404
1378
try :
1405
1379
description , type , default = self ._parser ._inidict [name ]
@@ -1432,13 +1406,7 @@ def _getini(self, name: str):
1432
1406
# a_line_list = ["tests", "acceptance"]
1433
1407
# in this case, we already have a list ready to use.
1434
1408
#
1435
- if type == "pathlist" :
1436
- # TODO: This assert is probably not valid in all cases.
1437
- assert self .inipath is not None
1438
- dp = self .inipath .parent
1439
- input_values = shlex .split (value ) if isinstance (value , str ) else value
1440
- return [legacy_path (str (dp / x )) for x in input_values ]
1441
- elif type == "paths" :
1409
+ if type == "paths" :
1442
1410
# TODO: This assert is probably not valid in all cases.
1443
1411
assert self .inipath is not None
1444
1412
dp = self .inipath .parent
@@ -1453,9 +1421,12 @@ def _getini(self, name: str):
1453
1421
return value
1454
1422
elif type == "bool" :
1455
1423
return _strtobool (str (value ).strip ())
1456
- else :
1457
- assert type in [None , "string" ]
1424
+ elif type == "string" :
1425
+ return value
1426
+ elif type is None :
1458
1427
return value
1428
+ else :
1429
+ return self ._getini_unknown_type (name , type , value )
1459
1430
1460
1431
def _getconftest_pathlist (
1461
1432
self , name : str , path : Path , rootpath : Path
0 commit comments