From 5e1c6ce6301aaa2806d089b4d89e85c6efb96c8b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 12 Jan 2020 20:09:51 +0100 Subject: [PATCH 1/5] tox: linting: pass posargs --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index d33a622241c..bc0646d123a 100644 --- a/tox.ini +++ b/tox.ini @@ -53,7 +53,7 @@ deps = skip_install = True basepython = python3 deps = pre-commit>=1.11.0 -commands = pre-commit run --all-files --show-diff-on-failure +commands = pre-commit run --all-files --show-diff-on-failure {posargs:} [testenv:docs] basepython = python3 From 117072d64c395283f8e035ed4dc44e838623c119 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 12 Jan 2020 22:17:49 +0100 Subject: [PATCH 2/5] typing: fix _pytest.config.findpaths.determine_setup --- src/_pytest/config/findpaths.py | 2 +- testing/test_config.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index f06c9cfffb1..728246dfcc5 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -108,7 +108,7 @@ def get_dir_from_path(path): def determine_setup( - inifile: str, + inifile: Optional[str], args: List[str], rootdir_cmd_arg: Optional[str] = None, config: Optional["Config"] = None, diff --git a/testing/test_config.py b/testing/test_config.py index 9735fc17696..29bd45c6c0f 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -859,7 +859,7 @@ def test_simple_noini(self, tmpdir): 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): + def test_with_ini(self, tmpdir, name) -> None: inifile = tmpdir.join(name) inifile.write("[pytest]\n" if name != "setup.cfg" else "[tool:pytest]\n") @@ -874,7 +874,7 @@ def test_with_ini(self, tmpdir, name): assert inifile == inifile @pytest.mark.parametrize("name", "setup.cfg tox.ini".split()) - def test_pytestini_overrides_empty_other(self, tmpdir, name): + def test_pytestini_overrides_empty_other(self, tmpdir, name) -> None: inifile = tmpdir.ensure("pytest.ini") a = tmpdir.mkdir("a") a.ensure(name) @@ -882,7 +882,7 @@ def test_pytestini_overrides_empty_other(self, tmpdir, name): assert rootdir == tmpdir assert inifile == inifile - def test_setuppy_fallback(self, tmpdir): + def test_setuppy_fallback(self, tmpdir) -> None: a = tmpdir.mkdir("a") a.ensure("setup.cfg") tmpdir.ensure("setup.py") @@ -891,14 +891,14 @@ def test_setuppy_fallback(self, tmpdir): assert inifile is None assert inicfg == {} - def test_nothing(self, tmpdir, monkeypatch): + def test_nothing(self, tmpdir, monkeypatch) -> None: monkeypatch.chdir(str(tmpdir)) rootdir, inifile, inicfg = determine_setup(None, [tmpdir]) assert rootdir == tmpdir assert inifile is None assert inicfg == {} - def test_with_specific_inifile(self, tmpdir): + def test_with_specific_inifile(self, tmpdir) -> None: inifile = tmpdir.ensure("pytest.ini") rootdir, inifile, inicfg = determine_setup(inifile, [tmpdir]) assert rootdir == tmpdir @@ -1039,7 +1039,7 @@ def test(): result = testdir.runpytest("--override-ini", "python_files=unittest_*.py") result.stdout.fnmatch_lines(["*1 passed in*"]) - def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch): + def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch) -> None: monkeypatch.chdir(str(tmpdir)) a = tmpdir.mkdir("a") b = tmpdir.mkdir("b") @@ -1047,7 +1047,7 @@ def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch): assert rootdir == tmpdir assert inifile is None - def test_with_arg_outside_cwd_with_inifile(self, tmpdir): + def test_with_arg_outside_cwd_with_inifile(self, tmpdir) -> None: a = tmpdir.mkdir("a") b = tmpdir.mkdir("b") inifile = a.ensure("pytest.ini") @@ -1056,13 +1056,13 @@ def test_with_arg_outside_cwd_with_inifile(self, tmpdir): assert inifile == parsed_inifile @pytest.mark.parametrize("dirs", ([], ["does-not-exist"], ["a/does-not-exist"])) - def test_with_non_dir_arg(self, dirs, tmpdir): + def test_with_non_dir_arg(self, dirs, tmpdir) -> None: with tmpdir.ensure(dir=True).as_cwd(): rootdir, inifile, inicfg = determine_setup(None, dirs) assert rootdir == tmpdir assert inifile is None - def test_with_existing_file_in_subdir(self, tmpdir): + def test_with_existing_file_in_subdir(self, tmpdir) -> None: a = tmpdir.mkdir("a") a.ensure("exist") with tmpdir.as_cwd(): From 090e26051738314317fbe7e6fc603e1cf39d6c87 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 2 Dec 2019 18:01:08 +0200 Subject: [PATCH 3/5] master: update mypy 0.740 -> 0.761 (cherry picked from commit 16ff9f591e38d1f2a79441f177130b1d89098c6e) (cherry picked from commit 4848bbdf9a4480ec85b520c6f3224256f1346679) --- .pre-commit-config.yaml | 2 +- src/_pytest/_code/code.py | 2 +- src/_pytest/assertion/__init__.py | 2 +- src/_pytest/assertion/rewrite.py | 5 ++--- src/_pytest/compat.py | 7 ++----- src/_pytest/doctest.py | 4 +++- src/_pytest/pytester.py | 2 +- src/_pytest/reports.py | 2 +- src/_pytest/runner.py | 2 +- testing/code/test_source.py | 8 ++------ 10 files changed, 15 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4ebbd6d1886..67b10c6af2c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,7 +37,7 @@ repos: - id: pyupgrade args: [--py3-plus] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.740 + rev: v0.761 hooks: - id: mypy files: ^(src/|testing/) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index a8f11736607..d1a8ec2f1e4 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -479,7 +479,7 @@ def from_current( assert tup[1] is not None, "no current exception" assert tup[2] is not None, "no current exception" exc_info = (tup[0], tup[1], tup[2]) - return cls.from_exc_info(exc_info, exprinfo) + return ExceptionInfo.from_exc_info(exc_info, exprinfo) @classmethod def for_later(cls) -> "ExceptionInfo[_E]": diff --git a/src/_pytest/assertion/__init__.py b/src/_pytest/assertion/__init__.py index 34d6701ed03..f96afce6d05 100644 --- a/src/_pytest/assertion/__init__.py +++ b/src/_pytest/assertion/__init__.py @@ -33,7 +33,7 @@ def pytest_addoption(parser): ) -def register_assert_rewrite(*names): +def register_assert_rewrite(*names) -> None: """Register one or more module names to be rewritten on import. This function will make sure that this module or all modules inside diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 77ae7041176..ab5e63a1e0c 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -1045,14 +1045,13 @@ def try_makedirs(cache_dir) -> bool: def get_cache_dir(file_path: Path) -> Path: """Returns the cache directory to write .pyc files for the given .py file path""" - # Type ignored until added in next mypy release. - if sys.version_info >= (3, 8) and sys.pycache_prefix: # type: ignore + if sys.version_info >= (3, 8) and sys.pycache_prefix: # given: # prefix = '/tmp/pycs' # path = '/home/user/proj/test_app.py' # we want: # '/tmp/pycs/home/user/proj' - return Path(sys.pycache_prefix) / Path(*file_path.parts[1:-1]) # type: ignore + return Path(sys.pycache_prefix) / Path(*file_path.parts[1:-1]) else: # classic pycache directory return file_path.parent / "__pycache__" diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index fc810b3e510..8dd74b577a4 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -43,8 +43,7 @@ if sys.version_info >= (3, 8): - # Type ignored until next mypy release. - from importlib import metadata as importlib_metadata # type: ignore + from importlib import metadata as importlib_metadata else: import importlib_metadata # noqa: F401 @@ -385,9 +384,7 @@ def overload(f): # noqa: F811 if sys.version_info >= (3, 8): - # TODO: Remove type ignore on next mypy update. - # https://github.com/python/typeshed/commit/add0b5e930a1db16560fde45a3b710eefc625709 - from functools import cached_property # type: ignore + from functools import cached_property else: class cached_property(Generic[_S, _T]): diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index c81f0bfd4d4..488e91ddbbf 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -445,7 +445,9 @@ def _find_lineno(self, obj, source_lines): obj = getattr(obj, "fget", obj) return doctest.DocTestFinder._find_lineno(self, obj, source_lines) - def _find(self, tests, obj, name, module, source_lines, globs, seen): + def _find( + self, tests, obj, name, module, source_lines, globs, seen + ) -> None: if _is_mocked(obj): return with _patch_unwrap_mock_aware(): diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index c279fca88ae..930f7db2946 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -832,7 +832,7 @@ def inline_genitems(self, *args): items = [x.item for x in rec.getcalls("pytest_itemcollected")] return items, rec - def inline_run(self, *args, plugins=(), no_reraise_ctrlc=False): + def inline_run(self, *args, plugins=(), no_reraise_ctrlc: bool = False): """Run ``pytest.main()`` in-process, returning a HookRecorder. Runs the :py:func:`pytest.main` function to run all of pytest inside diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index 4c93013d617..ad63e21a902 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -259,7 +259,7 @@ def __repr__(self): ) @classmethod - def from_item_and_call(cls, item, call): + def from_item_and_call(cls, item, call) -> "TestReport": """ Factory method to create and fill a TestReport with standard item and call info. """ diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 67e28e905e1..50e4d4307ad 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -250,7 +250,7 @@ def pytest_runtest_makereport(item, call): return TestReport.from_item_and_call(item, call) -def pytest_make_collect_report(collector): +def pytest_make_collect_report(collector) -> CollectReport: call = CallInfo.from_call(lambda: list(collector.collect()), "collect") longrepr = None if not call.excinfo: diff --git a/testing/code/test_source.py b/testing/code/test_source.py index bf52dccd791..1390d8b0ac5 100644 --- a/testing/code/test_source.py +++ b/testing/code/test_source.py @@ -318,16 +318,12 @@ def test_compile_and_getsource(self) -> None: @pytest.mark.parametrize("name", ["", None, "my"]) def test_compilefuncs_and_path_sanity(self, name: Optional[str]) -> None: - def check(comp, name): + def check(comp, name) -> None: co = comp(self.source, name) if not name: expected = "codegen %s:%d>" % (mypath, mylineno + 2 + 2) # type: ignore else: - expected = "codegen %r %s:%d>" % ( - name, - mypath, # type: ignore - mylineno + 2 + 2, # type: ignore - ) # type: ignore + expected = "codegen %r %s:%d>" % (name, mypath, mylineno + 2 + 2) # type: ignore fn = co.co_filename assert fn.endswith(expected) From 4ff7453b482ca99a1481b096c96d9447fb2b4b93 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 10 Jan 2020 20:18:12 +0100 Subject: [PATCH 4/5] ci: Travis: Python 3.5.1 via Trusty Python 3.5.0 caused flaky failures before (https://github.com/pytest-dev/pytest/issues/5795). This is pulled out of https://github.com/pytest-dev/pytest/pull/6435, which adds code specific for Python < 3.5.2. It only runs a specific test, while collecting everything to get coverage of the version specific code around typing. --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 35ca8a69c97..5b67f15dd59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,8 +52,10 @@ jobs: - env: TOXENV=pypy3-xdist python: 'pypy3' - - env: TOXENV=py35-xdist - python: '3.5' + # Coverage for Python 3.5.{0,1} specific code, mostly typing related. + - env: TOXENV=py35 PYTEST_COVERAGE=1 PYTEST_ADDOPTS="-k test_raises_cyclic_reference" + python: '3.5.1' + dist: trusty # Specialized factors for py37. - env: TOXENV=py37-pluggymaster-xdist From f0c7f21312ca1445aefedcf25f2d54f2cdfe1924 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 12 Jan 2020 20:35:20 +0100 Subject: [PATCH 5/5] Remove "pragma: no cover" comments --- src/_pytest/compat.py | 2 +- testing/python/raises.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 8dd74b577a4..de640bdd180 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -371,7 +371,7 @@ def getvalue(self) -> str: return self.buffer.getvalue().decode("UTF-8") -if sys.version_info < (3, 5, 2): # pragma: no cover +if sys.version_info < (3, 5, 2): def overload(f): # noqa: F811 return f diff --git a/testing/python/raises.py b/testing/python/raises.py index 1c701796af2..cfdbe6748f4 100644 --- a/testing/python/raises.py +++ b/testing/python/raises.py @@ -166,7 +166,7 @@ def __call__(self): # Early versions of Python 3.5 have some bug causing the # __call__ frame to still refer to t even after everything # is done. This makes the test pass for them. - if sys.version_info < (3, 5, 2): # pragma: no cover + if sys.version_info < (3, 5, 2): del self raise ValueError