From 161ba87300ab5b49efa2833cd0e39bba301c2712 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 23 Jul 2023 13:36:42 +0300 Subject: [PATCH 1/3] doc/usage: clarify "Run tests by node ids" Fix #11107, #11235. --- doc/en/how-to/usage.rst | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/doc/en/how-to/usage.rst b/doc/en/how-to/usage.rst index 4ec4459a2..03afb22d6 100644 --- a/doc/en/how-to/usage.rst +++ b/doc/en/how-to/usage.rst @@ -46,21 +46,28 @@ Use ``""`` instead of ``''`` in expression when running this on Windows **Run tests by node ids** -Each collected test is assigned a unique ``nodeid`` which consist of the module filename followed -by specifiers like class names, function names and parameters from parametrization, separated by ``::`` characters. +Each collected test is assigned a unique ``nodeid`` which consist of the module file path followed +by specifiers like class names and function names separated by ``::`` characters, +and parameters from parametrization in ``[...]``. +You can use the same syntax to match tests relative to the working directory. To run a specific test within a module: .. code-block:: bash - pytest test_mod.py::test_func + pytest tests/test_mod.py::test_func - -Another example specifying a test method in the command line: +To run all tests in a class: .. code-block:: bash - pytest test_mod.py::TestClass::test_method + pytest tests/test_mod.py::TestClass + +Specifying a specific test method: + +.. code-block:: bash + + pytest tests/test_mod.py::TestClass::test_method **Run tests by marker expressions** From 4e42421ebf2938bfac01e271afb195c2323566fd Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 23 Jul 2023 13:54:03 +0300 Subject: [PATCH 2/3] config: fix an incorrect type Was a mistake in d97d44a97af2303eb3f3aea1f16fd834f5415509. --- src/_pytest/config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 1f4670a56..88b23f1a4 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1243,7 +1243,7 @@ class Config: self, *, args: List[str], - pyargs: List[str], + pyargs: bool, testpaths: List[str], invocation_dir: Path, rootpath: Path, From 13e2b002583b0f3e8541b4b1201c10b8c330a865 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 23 Jul 2023 14:10:26 +0300 Subject: [PATCH 3/3] config: don't pass the entire Config to `determine_setup()` Seems better to make the function a bit more pure, and avoids the circular import. --- src/_pytest/config/__init__.py | 2 +- src/_pytest/config/findpaths.py | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 88b23f1a4..be62fe999 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1170,7 +1170,7 @@ class Config: ns.inifilename, ns.file_or_dir + unknown_args, rootdir_cmd_arg=ns.rootdir or None, - config=self, + invocation_dir=self.invocation_params.dir, ) self._rootpath = rootpath self._inipath = inipath diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index 234b9e129..9c76947a4 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -7,7 +7,6 @@ from typing import List from typing import Optional from typing import Sequence from typing import Tuple -from typing import TYPE_CHECKING from typing import Union import iniconfig @@ -17,9 +16,6 @@ from _pytest.outcomes import fail from _pytest.pathlib import absolutepath from _pytest.pathlib import commonpath -if TYPE_CHECKING: - from . import Config - def _parse_ini_config(path: Path) -> iniconfig.IniConfig: """Parse the given generic '.ini' file using legacy IniConfig parser, returning @@ -176,8 +172,21 @@ def determine_setup( inifile: Optional[str], args: Sequence[str], rootdir_cmd_arg: Optional[str] = None, - config: Optional["Config"] = None, + invocation_dir: Optional[Path] = None, ) -> Tuple[Path, Optional[Path], Dict[str, Union[str, List[str]]]]: + """Determine the rootdir, inifile and ini configuration values from the + command line arguments. + + :param inifile: + The `--inifile` command line argument, if given. + :param args: + The free command line arguments. + :param rootdir_cmd_arg: + The `--rootdir` command line argument, if given. + :param invocation_dir: + The working directory when pytest was invoked, if known. + If not known, the current working directory is used. + """ rootdir = None dirs = get_dirs_from_args(args) if inifile: @@ -198,8 +207,8 @@ def determine_setup( if dirs != [ancestor]: rootdir, inipath, inicfg = locate_config(dirs) if rootdir is None: - if config is not None: - cwd = config.invocation_params.dir + if invocation_dir is not None: + cwd = invocation_dir else: cwd = Path.cwd() rootdir = get_common_ancestor([cwd, ancestor])