Skip to content

Commit 430ad14

Browse files
authored
Merge pull request #11244 from bluetech/rootdir-tweaks
Rootdir tweaks
2 parents f2b6040 + 13e2b00 commit 430ad14

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

doc/en/how-to/usage.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,28 @@ Use ``""`` instead of ``''`` in expression when running this on Windows
4646

4747
**Run tests by node ids**
4848

49-
Each collected test is assigned a unique ``nodeid`` which consist of the module filename followed
50-
by specifiers like class names, function names and parameters from parametrization, separated by ``::`` characters.
49+
Each collected test is assigned a unique ``nodeid`` which consist of the module file path followed
50+
by specifiers like class names and function names separated by ``::`` characters,
51+
and parameters from parametrization in ``[...]``.
52+
You can use the same syntax to match tests relative to the working directory.
5153

5254
To run a specific test within a module:
5355

5456
.. code-block:: bash
5557
56-
pytest test_mod.py::test_func
58+
pytest tests/test_mod.py::test_func
5759
60+
To run all tests in a class:
5861

59-
Another example specifying a test method in the command line:
62+
.. code-block:: bash
63+
64+
pytest tests/test_mod.py::TestClass
65+
66+
Specifying a specific test method:
6067

6168
.. code-block:: bash
6269
63-
pytest test_mod.py::TestClass::test_method
70+
pytest tests/test_mod.py::TestClass::test_method
6471
6572
**Run tests by marker expressions**
6673

src/_pytest/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ def _initini(self, args: Sequence[str]) -> None:
11701170
ns.inifilename,
11711171
ns.file_or_dir + unknown_args,
11721172
rootdir_cmd_arg=ns.rootdir or None,
1173-
config=self,
1173+
invocation_dir=self.invocation_params.dir,
11741174
)
11751175
self._rootpath = rootpath
11761176
self._inipath = inipath
@@ -1243,7 +1243,7 @@ def _decide_args(
12431243
self,
12441244
*,
12451245
args: List[str],
1246-
pyargs: List[str],
1246+
pyargs: bool,
12471247
testpaths: List[str],
12481248
invocation_dir: Path,
12491249
rootpath: Path,

src/_pytest/config/findpaths.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import Optional
88
from typing import Sequence
99
from typing import Tuple
10-
from typing import TYPE_CHECKING
1110
from typing import Union
1211

1312
import iniconfig
@@ -17,9 +16,6 @@
1716
from _pytest.pathlib import absolutepath
1817
from _pytest.pathlib import commonpath
1918

20-
if TYPE_CHECKING:
21-
from . import Config
22-
2319

2420
def _parse_ini_config(path: Path) -> iniconfig.IniConfig:
2521
"""Parse the given generic '.ini' file using legacy IniConfig parser, returning
@@ -176,8 +172,21 @@ def determine_setup(
176172
inifile: Optional[str],
177173
args: Sequence[str],
178174
rootdir_cmd_arg: Optional[str] = None,
179-
config: Optional["Config"] = None,
175+
invocation_dir: Optional[Path] = None,
180176
) -> Tuple[Path, Optional[Path], Dict[str, Union[str, List[str]]]]:
177+
"""Determine the rootdir, inifile and ini configuration values from the
178+
command line arguments.
179+
180+
:param inifile:
181+
The `--inifile` command line argument, if given.
182+
:param args:
183+
The free command line arguments.
184+
:param rootdir_cmd_arg:
185+
The `--rootdir` command line argument, if given.
186+
:param invocation_dir:
187+
The working directory when pytest was invoked, if known.
188+
If not known, the current working directory is used.
189+
"""
181190
rootdir = None
182191
dirs = get_dirs_from_args(args)
183192
if inifile:
@@ -198,8 +207,8 @@ def determine_setup(
198207
if dirs != [ancestor]:
199208
rootdir, inipath, inicfg = locate_config(dirs)
200209
if rootdir is None:
201-
if config is not None:
202-
cwd = config.invocation_params.dir
210+
if invocation_dir is not None:
211+
cwd = invocation_dir
203212
else:
204213
cwd = Path.cwd()
205214
rootdir = get_common_ancestor([cwd, ancestor])

0 commit comments

Comments
 (0)