13
13
import importlib .metadata
14
14
import inspect
15
15
import os
16
- from pathlib import Path
16
+ import pathlib
17
17
import re
18
18
import shlex
19
19
import sys
@@ -114,7 +114,7 @@ class ExitCode(enum.IntEnum):
114
114
class ConftestImportFailure (Exception ):
115
115
def __init__ (
116
116
self ,
117
- path : Path ,
117
+ path : pathlib . Path ,
118
118
* ,
119
119
cause : Exception ,
120
120
) -> None :
@@ -290,7 +290,7 @@ def get_config(
290
290
invocation_params = Config .InvocationParams (
291
291
args = args or (),
292
292
plugins = plugins ,
293
- dir = Path .cwd (),
293
+ dir = pathlib . Path .cwd (),
294
294
),
295
295
)
296
296
@@ -347,7 +347,7 @@ def _prepareconfig(
347
347
raise
348
348
349
349
350
- def _get_directory (path : Path ) -> Path :
350
+ def _get_directory (path : pathlib . Path ) -> pathlib . Path :
351
351
"""Get the directory of a path - itself if already a directory."""
352
352
if path .is_file ():
353
353
return path .parent
@@ -408,9 +408,9 @@ def __init__(self) -> None:
408
408
# All conftest modules applicable for a directory.
409
409
# This includes the directory's own conftest modules as well
410
410
# as those of its parent directories.
411
- self ._dirpath2confmods : dict [Path , list [types .ModuleType ]] = {}
411
+ self ._dirpath2confmods : dict [pathlib . Path , list [types .ModuleType ]] = {}
412
412
# Cutoff directory above which conftests are no longer discovered.
413
- self ._confcutdir : Path | None = None
413
+ self ._confcutdir : pathlib . Path | None = None
414
414
# If set, conftest loading is skipped.
415
415
self ._noconftest = False
416
416
@@ -544,12 +544,12 @@ def pytest_configure(self, config: Config) -> None:
544
544
#
545
545
def _set_initial_conftests (
546
546
self ,
547
- args : Sequence [str | Path ],
547
+ args : Sequence [str | pathlib . Path ],
548
548
pyargs : bool ,
549
549
noconftest : bool ,
550
- rootpath : Path ,
551
- confcutdir : Path | None ,
552
- invocation_dir : Path ,
550
+ rootpath : pathlib . Path ,
551
+ confcutdir : pathlib . Path | None ,
552
+ invocation_dir : pathlib . Path ,
553
553
importmode : ImportMode | str ,
554
554
* ,
555
555
consider_namespace_packages : bool ,
@@ -593,7 +593,7 @@ def _set_initial_conftests(
593
593
consider_namespace_packages = consider_namespace_packages ,
594
594
)
595
595
596
- def _is_in_confcutdir (self , path : Path ) -> bool :
596
+ def _is_in_confcutdir (self , path : pathlib . Path ) -> bool :
597
597
"""Whether to consider the given path to load conftests from."""
598
598
if self ._confcutdir is None :
599
599
return True
@@ -610,9 +610,9 @@ def _is_in_confcutdir(self, path: Path) -> bool:
610
610
611
611
def _try_load_conftest (
612
612
self ,
613
- anchor : Path ,
613
+ anchor : pathlib . Path ,
614
614
importmode : str | ImportMode ,
615
- rootpath : Path ,
615
+ rootpath : pathlib . Path ,
616
616
* ,
617
617
consider_namespace_packages : bool ,
618
618
) -> None :
@@ -635,9 +635,9 @@ def _try_load_conftest(
635
635
636
636
def _loadconftestmodules (
637
637
self ,
638
- path : Path ,
638
+ path : pathlib . Path ,
639
639
importmode : str | ImportMode ,
640
- rootpath : Path ,
640
+ rootpath : pathlib . Path ,
641
641
* ,
642
642
consider_namespace_packages : bool ,
643
643
) -> None :
@@ -665,14 +665,14 @@ def _loadconftestmodules(
665
665
clist .append (mod )
666
666
self ._dirpath2confmods [directory ] = clist
667
667
668
- def _getconftestmodules (self , path : Path ) -> Sequence [types .ModuleType ]:
668
+ def _getconftestmodules (self , path : pathlib . Path ) -> Sequence [types .ModuleType ]:
669
669
directory = self ._get_directory (path )
670
670
return self ._dirpath2confmods .get (directory , ())
671
671
672
672
def _rget_with_confmod (
673
673
self ,
674
674
name : str ,
675
- path : Path ,
675
+ path : pathlib . Path ,
676
676
) -> tuple [types .ModuleType , Any ]:
677
677
modules = self ._getconftestmodules (path )
678
678
for mod in reversed (modules ):
@@ -684,9 +684,9 @@ def _rget_with_confmod(
684
684
685
685
def _importconftest (
686
686
self ,
687
- conftestpath : Path ,
687
+ conftestpath : pathlib . Path ,
688
688
importmode : str | ImportMode ,
689
- rootpath : Path ,
689
+ rootpath : pathlib . Path ,
690
690
* ,
691
691
consider_namespace_packages : bool ,
692
692
) -> types .ModuleType :
@@ -738,7 +738,7 @@ def _importconftest(
738
738
def _check_non_top_pytest_plugins (
739
739
self ,
740
740
mod : types .ModuleType ,
741
- conftestpath : Path ,
741
+ conftestpath : pathlib . Path ,
742
742
) -> None :
743
743
if (
744
744
hasattr (mod , "pytest_plugins" )
@@ -995,15 +995,15 @@ class InvocationParams:
995
995
"""The command-line arguments as passed to :func:`pytest.main`."""
996
996
plugins : Sequence [str | _PluggyPlugin ] | None
997
997
"""Extra plugins, might be `None`."""
998
- dir : Path
999
- """The directory from which :func:`pytest.main` was invoked."""
998
+ dir : pathlib . Path
999
+ """The directory from which :func:`pytest.main` was invoked. :type: pathlib.Path """
1000
1000
1001
1001
def __init__ (
1002
1002
self ,
1003
1003
* ,
1004
1004
args : Iterable [str ],
1005
1005
plugins : Sequence [str | _PluggyPlugin ] | None ,
1006
- dir : Path ,
1006
+ dir : pathlib . Path ,
1007
1007
) -> None :
1008
1008
object .__setattr__ (self , "args" , tuple (args ))
1009
1009
object .__setattr__ (self , "plugins" , plugins )
@@ -1037,7 +1037,7 @@ def __init__(
1037
1037
1038
1038
if invocation_params is None :
1039
1039
invocation_params = self .InvocationParams (
1040
- args = (), plugins = None , dir = Path .cwd ()
1040
+ args = (), plugins = None , dir = pathlib . Path .cwd ()
1041
1041
)
1042
1042
1043
1043
self .option = argparse .Namespace ()
@@ -1088,7 +1088,7 @@ def __init__(
1088
1088
self .args : list [str ] = []
1089
1089
1090
1090
@property
1091
- def rootpath (self ) -> Path :
1091
+ def rootpath (self ) -> pathlib . Path :
1092
1092
"""The path to the :ref:`rootdir <rootdir>`.
1093
1093
1094
1094
:type: pathlib.Path
@@ -1098,11 +1098,9 @@ def rootpath(self) -> Path:
1098
1098
return self ._rootpath
1099
1099
1100
1100
@property
1101
- def inipath (self ) -> Path | None :
1101
+ def inipath (self ) -> pathlib . Path | None :
1102
1102
"""The path to the :ref:`configfile <configfiles>`.
1103
1103
1104
- :type: Optional[pathlib.Path]
1105
-
1106
1104
.. versionadded:: 6.1
1107
1105
"""
1108
1106
return self ._inipath
@@ -1313,8 +1311,8 @@ def _decide_args(
1313
1311
args : list [str ],
1314
1312
pyargs : bool ,
1315
1313
testpaths : list [str ],
1316
- invocation_dir : Path ,
1317
- rootpath : Path ,
1314
+ invocation_dir : pathlib . Path ,
1315
+ rootpath : pathlib . Path ,
1318
1316
warn : bool ,
1319
1317
) -> tuple [list [str ], ArgsSource ]:
1320
1318
"""Decide the args (initial paths/nodeids) to use given the relevant inputs.
@@ -1640,17 +1638,19 @@ def _getini(self, name: str):
1640
1638
else :
1641
1639
return self ._getini_unknown_type (name , type , value )
1642
1640
1643
- def _getconftest_pathlist (self , name : str , path : Path ) -> list [Path ] | None :
1641
+ def _getconftest_pathlist (
1642
+ self , name : str , path : pathlib .Path
1643
+ ) -> list [pathlib .Path ] | None :
1644
1644
try :
1645
1645
mod , relroots = self .pluginmanager ._rget_with_confmod (name , path )
1646
1646
except KeyError :
1647
1647
return None
1648
1648
assert mod .__file__ is not None
1649
- modpath = Path (mod .__file__ ).parent
1650
- values : list [Path ] = []
1649
+ modpath = pathlib . Path (mod .__file__ ).parent
1650
+ values : list [pathlib . Path ] = []
1651
1651
for relroot in relroots :
1652
1652
if isinstance (relroot , os .PathLike ):
1653
- relroot = Path (relroot )
1653
+ relroot = pathlib . Path (relroot )
1654
1654
else :
1655
1655
relroot = relroot .replace ("/" , os .sep )
1656
1656
relroot = absolutepath (modpath / relroot )
0 commit comments