From d2f9a73a299c0c15280e072c9b3183870e0b1e4b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 25 Feb 2020 02:15:26 +0100 Subject: [PATCH 1/5] typing: get_dirs_from_args --- src/_pytest/config/findpaths.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index fb84160c1..d63071084 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -86,14 +86,14 @@ def get_common_ancestor(paths: Iterable[py.path.local]) -> py.path.local: return common_ancestor -def get_dirs_from_args(args): - def is_option(x): - return str(x).startswith("-") +def get_dirs_from_args(args: List[str]) -> List[py.path.local]: + def is_option(x: str) -> bool: + return x.startswith("-") - def get_file_part_from_node_id(x): - return str(x).split("::")[0] + def get_file_part_from_node_id(x: str) -> str: + return x.split("::")[0] - def get_dir_from_path(path): + def get_dir_from_path(path: py.path.local) -> py.path.local: if path.isdir(): return path return py.path.local(path.dirname) From 6c236767e03b2d3005604ed668072be0687325f3 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 25 Feb 2020 03:32:46 +0100 Subject: [PATCH 2/5] Adjust/fix test_config: use strs with determine_setup --- testing/test_config.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/testing/test_config.py b/testing/test_config.py index be728c0fc..42c1a85b8 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -3,6 +3,8 @@ import re import sys import textwrap +import py.path + import _pytest._code import pytest from _pytest.compat import importlib_metadata @@ -900,55 +902,55 @@ class TestRootdir: assert get_common_ancestor([no_path.join("a")]) == tmpdir @pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split()) - def test_with_ini(self, tmpdir, name) -> None: + def test_with_ini(self, tmpdir: py.path.local, name: str) -> None: inifile = tmpdir.join(name) inifile.write("[pytest]\n" if name != "setup.cfg" else "[tool:pytest]\n") a = tmpdir.mkdir("a") b = a.mkdir("b") - for args in ([tmpdir], [a], [b]): + for args in ([str(tmpdir)], [str(a)], [str(b)]): rootdir, parsed_inifile, _ = determine_setup(None, args) assert rootdir == tmpdir assert parsed_inifile == inifile - rootdir, parsed_inifile, _ = determine_setup(None, [b, a]) + rootdir, parsed_inifile, _ = determine_setup(None, [str(b), str(a)]) assert rootdir == tmpdir assert parsed_inifile == inifile @pytest.mark.parametrize("name", "setup.cfg tox.ini".split()) - def test_pytestini_overrides_empty_other(self, tmpdir, name) -> None: + def test_pytestini_overrides_empty_other(self, tmpdir: py.path.local, name) -> None: inifile = tmpdir.ensure("pytest.ini") a = tmpdir.mkdir("a") a.ensure(name) - rootdir, parsed_inifile, _ = determine_setup(None, [a]) + rootdir, parsed_inifile, _ = determine_setup(None, [str(a)]) assert rootdir == tmpdir assert parsed_inifile == inifile - def test_setuppy_fallback(self, tmpdir) -> None: + def test_setuppy_fallback(self, tmpdir: py.path.local) -> None: a = tmpdir.mkdir("a") a.ensure("setup.cfg") tmpdir.ensure("setup.py") - rootdir, inifile, inicfg = determine_setup(None, [a]) + rootdir, inifile, inicfg = determine_setup(None, [str(a)]) assert rootdir == tmpdir assert inifile is None assert inicfg == {} - def test_nothing(self, tmpdir, monkeypatch) -> None: + def test_nothing(self, tmpdir: py.path.local, monkeypatch) -> None: monkeypatch.chdir(str(tmpdir)) - rootdir, inifile, inicfg = determine_setup(None, [tmpdir]) + rootdir, inifile, inicfg = determine_setup(None, [str(tmpdir)]) assert rootdir == tmpdir assert inifile is None assert inicfg == {} - def test_with_specific_inifile(self, tmpdir) -> None: + def test_with_specific_inifile(self, tmpdir: py.path.local) -> None: inifile = tmpdir.ensure("pytest.ini") - rootdir, _, _ = determine_setup(inifile, [tmpdir]) + rootdir, _, _ = determine_setup(str(inifile), [str(tmpdir)]) assert rootdir == tmpdir def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch) -> None: monkeypatch.chdir(str(tmpdir)) a = tmpdir.mkdir("a") b = tmpdir.mkdir("b") - rootdir, inifile, _ = determine_setup(None, [a, b]) + rootdir, inifile, _ = determine_setup(None, [str(a), str(b)]) assert rootdir == tmpdir assert inifile is None @@ -956,7 +958,7 @@ class TestRootdir: a = tmpdir.mkdir("a") b = tmpdir.mkdir("b") inifile = a.ensure("pytest.ini") - rootdir, parsed_inifile, _ = determine_setup(None, [a, b]) + rootdir, parsed_inifile, _ = determine_setup(None, [str(a), str(b)]) assert rootdir == a assert inifile == parsed_inifile From 6092d3c6e1c99be7a424db72ea144aa8caa0862e Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 25 Feb 2020 03:47:06 +0100 Subject: [PATCH 3/5] typing: parseconfig --- src/_pytest/pytester.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index f383e51f6..1d6fbbd96 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -29,6 +29,7 @@ from _pytest.capture import MultiCapture from _pytest.capture import SysCapture from _pytest.compat import TYPE_CHECKING from _pytest.config import _PluggyPlugin +from _pytest.config import Config from _pytest.config import ExitCode from _pytest.fixtures import FixtureRequest from _pytest.main import Session @@ -975,7 +976,7 @@ class Testdir: args.append("--basetemp=%s" % self.tmpdir.dirpath("basetemp")) return args - def parseconfig(self, *args): + def parseconfig(self, *args: Union[str, py.path.local]) -> Config: """Return a new pytest Config instance from given commandline args. This invokes the pytest bootstrapping code in _pytest.config to create @@ -991,7 +992,7 @@ class Testdir: import _pytest.config - config = _pytest.config._prepareconfig(args, self.plugins) + config = _pytest.config._prepareconfig(args, self.plugins) # type: Config # we don't know what the test will do with this half-setup config # object and thus we make sure it gets unconfigured properly in any # case (otherwise capturing could still be active, for example) From 8128f4b3b849d3ea42591f107017b008c168adf1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 25 Feb 2020 03:47:35 +0100 Subject: [PATCH 4/5] Fix test_write_pyc: passed list to parseconfig --- testing/test_assertrewrite.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 91a3a35e2..99328c6f9 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -23,6 +23,7 @@ from _pytest.assertion.rewrite import PYTEST_TAG from _pytest.assertion.rewrite import rewrite_asserts from _pytest.config import ExitCode from _pytest.pathlib import Path +from _pytest.pytester import Testdir def setup_module(mod): @@ -956,11 +957,11 @@ class TestAssertionRewriteHookDetails: ) assert testdir.runpytest().ret == 0 - def test_write_pyc(self, testdir, tmpdir, monkeypatch): + def test_write_pyc(self, testdir: Testdir, tmpdir, monkeypatch) -> None: from _pytest.assertion.rewrite import _write_pyc from _pytest.assertion import AssertionState - config = testdir.parseconfig([]) + config = testdir.parseconfig() state = AssertionState(config, "rewrite") source_path = str(tmpdir.ensure("source.py")) pycpath = tmpdir.join("pyc").strpath From d99bfc18b85e243233e86360fbe6ec07e8287201 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 29 Feb 2020 11:39:33 +0100 Subject: [PATCH 5/5] Update src/_pytest/config/findpaths.py Co-Authored-By: Ran Benita --- src/_pytest/config/findpaths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index d63071084..56b25f10f 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -86,7 +86,7 @@ def get_common_ancestor(paths: Iterable[py.path.local]) -> py.path.local: return common_ancestor -def get_dirs_from_args(args: List[str]) -> List[py.path.local]: +def get_dirs_from_args(args: Iterable[str]) -> List[py.path.local]: def is_option(x: str) -> bool: return x.startswith("-")