1313import importlib .metadata
1414import inspect
1515import os
16- from pathlib import Path
16+ import pathlib
1717import re
1818import shlex
1919import sys
@@ -114,7 +114,7 @@ class ExitCode(enum.IntEnum):
114114class ConftestImportFailure (Exception ):
115115 def __init__ (
116116 self ,
117- path : Path ,
117+ path : pathlib . Path ,
118118 * ,
119119 cause : Exception ,
120120 ) -> None :
@@ -290,7 +290,7 @@ def get_config(
290290 invocation_params = Config .InvocationParams (
291291 args = args or (),
292292 plugins = plugins ,
293- dir = Path .cwd (),
293+ dir = pathlib . Path .cwd (),
294294 ),
295295 )
296296
@@ -347,7 +347,7 @@ def _prepareconfig(
347347 raise
348348
349349
350- def _get_directory (path : Path ) -> Path :
350+ def _get_directory (path : pathlib . Path ) -> pathlib . Path :
351351 """Get the directory of a path - itself if already a directory."""
352352 if path .is_file ():
353353 return path .parent
@@ -408,9 +408,9 @@ def __init__(self) -> None:
408408 # All conftest modules applicable for a directory.
409409 # This includes the directory's own conftest modules as well
410410 # as those of its parent directories.
411- self ._dirpath2confmods : dict [Path , list [types .ModuleType ]] = {}
411+ self ._dirpath2confmods : dict [pathlib . Path , list [types .ModuleType ]] = {}
412412 # Cutoff directory above which conftests are no longer discovered.
413- self ._confcutdir : Path | None = None
413+ self ._confcutdir : pathlib . Path | None = None
414414 # If set, conftest loading is skipped.
415415 self ._noconftest = False
416416
@@ -544,12 +544,12 @@ def pytest_configure(self, config: Config) -> None:
544544 #
545545 def _set_initial_conftests (
546546 self ,
547- args : Sequence [str | Path ],
547+ args : Sequence [str | pathlib . Path ],
548548 pyargs : bool ,
549549 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 ,
553553 importmode : ImportMode | str ,
554554 * ,
555555 consider_namespace_packages : bool ,
@@ -593,7 +593,7 @@ def _set_initial_conftests(
593593 consider_namespace_packages = consider_namespace_packages ,
594594 )
595595
596- def _is_in_confcutdir (self , path : Path ) -> bool :
596+ def _is_in_confcutdir (self , path : pathlib . Path ) -> bool :
597597 """Whether to consider the given path to load conftests from."""
598598 if self ._confcutdir is None :
599599 return True
@@ -610,9 +610,9 @@ def _is_in_confcutdir(self, path: Path) -> bool:
610610
611611 def _try_load_conftest (
612612 self ,
613- anchor : Path ,
613+ anchor : pathlib . Path ,
614614 importmode : str | ImportMode ,
615- rootpath : Path ,
615+ rootpath : pathlib . Path ,
616616 * ,
617617 consider_namespace_packages : bool ,
618618 ) -> None :
@@ -635,9 +635,9 @@ def _try_load_conftest(
635635
636636 def _loadconftestmodules (
637637 self ,
638- path : Path ,
638+ path : pathlib . Path ,
639639 importmode : str | ImportMode ,
640- rootpath : Path ,
640+ rootpath : pathlib . Path ,
641641 * ,
642642 consider_namespace_packages : bool ,
643643 ) -> None :
@@ -665,14 +665,14 @@ def _loadconftestmodules(
665665 clist .append (mod )
666666 self ._dirpath2confmods [directory ] = clist
667667
668- def _getconftestmodules (self , path : Path ) -> Sequence [types .ModuleType ]:
668+ def _getconftestmodules (self , path : pathlib . Path ) -> Sequence [types .ModuleType ]:
669669 directory = self ._get_directory (path )
670670 return self ._dirpath2confmods .get (directory , ())
671671
672672 def _rget_with_confmod (
673673 self ,
674674 name : str ,
675- path : Path ,
675+ path : pathlib . Path ,
676676 ) -> tuple [types .ModuleType , Any ]:
677677 modules = self ._getconftestmodules (path )
678678 for mod in reversed (modules ):
@@ -684,9 +684,9 @@ def _rget_with_confmod(
684684
685685 def _importconftest (
686686 self ,
687- conftestpath : Path ,
687+ conftestpath : pathlib . Path ,
688688 importmode : str | ImportMode ,
689- rootpath : Path ,
689+ rootpath : pathlib . Path ,
690690 * ,
691691 consider_namespace_packages : bool ,
692692 ) -> types .ModuleType :
@@ -738,7 +738,7 @@ def _importconftest(
738738 def _check_non_top_pytest_plugins (
739739 self ,
740740 mod : types .ModuleType ,
741- conftestpath : Path ,
741+ conftestpath : pathlib . Path ,
742742 ) -> None :
743743 if (
744744 hasattr (mod , "pytest_plugins" )
@@ -995,15 +995,15 @@ class InvocationParams:
995995 """The command-line arguments as passed to :func:`pytest.main`."""
996996 plugins : Sequence [str | _PluggyPlugin ] | None
997997 """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 """
10001000
10011001 def __init__ (
10021002 self ,
10031003 * ,
10041004 args : Iterable [str ],
10051005 plugins : Sequence [str | _PluggyPlugin ] | None ,
1006- dir : Path ,
1006+ dir : pathlib . Path ,
10071007 ) -> None :
10081008 object .__setattr__ (self , "args" , tuple (args ))
10091009 object .__setattr__ (self , "plugins" , plugins )
@@ -1037,7 +1037,7 @@ def __init__(
10371037
10381038 if invocation_params is None :
10391039 invocation_params = self .InvocationParams (
1040- args = (), plugins = None , dir = Path .cwd ()
1040+ args = (), plugins = None , dir = pathlib . Path .cwd ()
10411041 )
10421042
10431043 self .option = argparse .Namespace ()
@@ -1088,7 +1088,7 @@ def __init__(
10881088 self .args : list [str ] = []
10891089
10901090 @property
1091- def rootpath (self ) -> Path :
1091+ def rootpath (self ) -> pathlib . Path :
10921092 """The path to the :ref:`rootdir <rootdir>`.
10931093
10941094 :type: pathlib.Path
@@ -1098,11 +1098,9 @@ def rootpath(self) -> Path:
10981098 return self ._rootpath
10991099
11001100 @property
1101- def inipath (self ) -> Path | None :
1101+ def inipath (self ) -> pathlib . Path | None :
11021102 """The path to the :ref:`configfile <configfiles>`.
11031103
1104- :type: Optional[pathlib.Path]
1105-
11061104 .. versionadded:: 6.1
11071105 """
11081106 return self ._inipath
@@ -1313,8 +1311,8 @@ def _decide_args(
13131311 args : list [str ],
13141312 pyargs : bool ,
13151313 testpaths : list [str ],
1316- invocation_dir : Path ,
1317- rootpath : Path ,
1314+ invocation_dir : pathlib . Path ,
1315+ rootpath : pathlib . Path ,
13181316 warn : bool ,
13191317 ) -> tuple [list [str ], ArgsSource ]:
13201318 """Decide the args (initial paths/nodeids) to use given the relevant inputs.
@@ -1640,17 +1638,19 @@ def _getini(self, name: str):
16401638 else :
16411639 return self ._getini_unknown_type (name , type , value )
16421640
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 :
16441644 try :
16451645 mod , relroots = self .pluginmanager ._rget_with_confmod (name , path )
16461646 except KeyError :
16471647 return None
16481648 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 ] = []
16511651 for relroot in relroots :
16521652 if isinstance (relroot , os .PathLike ):
1653- relroot = Path (relroot )
1653+ relroot = pathlib . Path (relroot )
16541654 else :
16551655 relroot = relroot .replace ("/" , os .sep )
16561656 relroot = absolutepath (modpath / relroot )
0 commit comments