From 499ac8e7b41bceef170f6e7e2340955471946326 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 20 Jan 2020 23:08:09 +0200 Subject: [PATCH 1/2] Revert "Fix type errors after adding types to the `py` dependency" This reverts commit 930a158a6a4d58ceb37aff97fa476215a68c915e. Regression test from Bruno Oliveira. (cherry picked from commit fb99b5c66ee06ad0bd3336d8599448d1d3da4f7f) Co-Authored-By: Bruno Oliveira --- src/_pytest/config/argparsing.py | 8 ++++---- src/_pytest/config/findpaths.py | 7 ++----- src/_pytest/doctest.py | 2 +- src/_pytest/fixtures.py | 11 ++++------- src/_pytest/main.py | 8 ++++---- src/_pytest/nodes.py | 1 - testing/python/collect.py | 6 +++--- testing/test_nose.py | 14 ++++++++++++++ 8 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/_pytest/config/argparsing.py b/src/_pytest/config/argparsing.py index 8817c5749..7cbb676bd 100644 --- a/src/_pytest/config/argparsing.py +++ b/src/_pytest/config/argparsing.py @@ -82,8 +82,8 @@ class Parser: self.optparser = self._getparser() try_argcomplete(self.optparser) - strargs = [str(x) if isinstance(x, py.path.local) else x for x in args] - return self.optparser.parse_args(strargs, namespace=namespace) + args = [str(x) if isinstance(x, py.path.local) else x for x in args] + return self.optparser.parse_args(args, namespace=namespace) def _getparser(self) -> "MyOptionParser": from _pytest._argcomplete import filescompleter @@ -124,8 +124,8 @@ class Parser: the remaining arguments unknown at this point. """ optparser = self._getparser() - strargs = [str(x) if isinstance(x, py.path.local) else x for x in args] - return optparser.parse_known_args(strargs, namespace=namespace) + args = [str(x) if isinstance(x, py.path.local) else x for x in args] + return optparser.parse_known_args(args, namespace=namespace) def addini(self, name, help, type=None, default=None): """ register an ini-file option. diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index fb84160c1..707ce969d 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -1,9 +1,6 @@ import os -from typing import Any -from typing import Iterable from typing import List from typing import Optional -from typing import Tuple import py @@ -63,7 +60,7 @@ def getcfg(args, config=None): return None, None, None -def get_common_ancestor(paths: Iterable[py.path.local]) -> py.path.local: +def get_common_ancestor(paths): common_ancestor = None for path in paths: if not path.exists(): @@ -116,7 +113,7 @@ def determine_setup( args: List[str], rootdir_cmd_arg: Optional[str] = None, config: Optional["Config"] = None, -) -> Tuple[py.path.local, Optional[str], Any]: +): dirs = get_dirs_from_args(args) if inifile: iniconfig = py.iniconfig.IniConfig(inifile) diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index d7ca888cc..e62c5e17e 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -308,7 +308,7 @@ class DoctestItem(pytest.Item): else: return super().repr_failure(excinfo) - def reportinfo(self) -> Tuple[py.path.local, int, str]: + def reportinfo(self) -> Tuple[str, int, str]: return self.fspath, self.dtest.lineno, "[doctest] %s" % self.name diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index f0a1a2ed0..bae3d0716 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -351,7 +351,7 @@ class FixtureRequest: self.fixturename = None #: Scope string, one of "function", "class", "module", "session" self.scope = "function" - self._fixture_defs = {} # type: Dict[str, FixtureDef] + self._fixture_defs = {} # argname -> FixtureDef fixtureinfo = pyfuncitem._fixtureinfo self._arg2fixturedefs = fixtureinfo.name2fixturedefs.copy() self._arg2index = {} @@ -426,8 +426,7 @@ class FixtureRequest: @scopeproperty() def fspath(self) -> py.path.local: """ the file system path of the test module which collected this test. """ - # TODO: Remove ignore once _pyfuncitem is properly typed. - return self._pyfuncitem.fspath # type: ignore + return self._pyfuncitem.fspath @property def keywords(self): @@ -550,9 +549,7 @@ class FixtureRequest: source_lineno = frameinfo.lineno source_path = py.path.local(source_path) if source_path.relto(funcitem.config.rootdir): - source_path_str = source_path.relto(funcitem.config.rootdir) - else: - source_path_str = str(source_path) + source_path = source_path.relto(funcitem.config.rootdir) msg = ( "The requested fixture has no parameter defined for test:\n" " {}\n\n" @@ -561,7 +558,7 @@ class FixtureRequest: funcitem.nodeid, fixturedef.argname, getlocation(fixturedef.func, funcitem.config.rootdir), - source_path_str, + source_path, source_lineno, ) ) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index d6d512938..a0f180cac 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -367,9 +367,9 @@ class Failed(Exception): @attr.s class _bestrelpath_cache(dict): - path = attr.ib(type=py.path.local) + path = attr.ib() - def __missing__(self, path: py.path.local) -> str: + def __missing__(self, path: str) -> str: r = self.path.bestrelpath(path) # type: str self[path] = r return r @@ -399,7 +399,7 @@ class Session(nodes.FSCollector): self._node_cache = {} self._bestrelpathcache = _bestrelpath_cache( config.rootdir - ) # type: Dict[py.path.local, str] + ) # type: Dict[str, str] # Dirnames of pkgs with dunder-init files. self._pkg_roots = {} @@ -414,7 +414,7 @@ class Session(nodes.FSCollector): self.testscollected, ) - def _node_location_to_relpath(self, node_path: py.path.local) -> str: + def _node_location_to_relpath(self, node_path: str) -> str: # bestrelpath is a quite slow function return self._bestrelpathcache[node_path] diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index fc951d2bc..3cfbf4626 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -462,7 +462,6 @@ class Item(Node): @cached_property def location(self) -> Tuple[str, Optional[int], str]: location = self.reportinfo() - assert isinstance(location[0], py.path.local), location[0] fspath = self.session._node_location_to_relpath(location[0]) assert type(location[2]) is str return (fspath, location[1], location[2]) diff --git a/testing/python/collect.py b/testing/python/collect.py index a68738c81..6e9938227 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1018,10 +1018,10 @@ class TestReportInfo: def test_itemreport_reportinfo(self, testdir): testdir.makeconftest( """ - import pytest, py + import pytest class MyFunction(pytest.Function): def reportinfo(self): - return py.path.local("foo"), 42, "custom" + return "ABCDE", 42, "custom" def pytest_pycollect_makeitem(collector, name, obj): if name == "test_func": return MyFunction(name, parent=collector) @@ -1029,7 +1029,7 @@ class TestReportInfo: ) item = testdir.getitem("def test_func(): pass") item.config.pluginmanager.getplugin("runner") - assert item.location == ("foo", 42, "custom") + assert item.location == ("ABCDE", 42, "custom") def test_func_reportinfo(self, testdir): item = testdir.getitem("def test_func(): pass") diff --git a/testing/test_nose.py b/testing/test_nose.py index 8a30755c9..469c127af 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -375,3 +375,17 @@ def test_skip_test_with_unicode(testdir): ) result = testdir.runpytest() result.stdout.fnmatch_lines(["* 1 skipped *"]) + + +def test_issue_6517(testdir): + testdir.makepyfile( + """ + from nose.tools import raises + + @raises(RuntimeError) + def test_fail_without_tcp(): + raise RuntimeError + """ + ) + result = testdir.runpytest() + result.stdout.fnmatch_lines(["* 1 passed *"]) From fd1a51a23fa687cf344f3506dff6cde0166faf2c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 29 Jan 2020 02:30:55 +0100 Subject: [PATCH 2/2] Preparing release version 5.3.5 --- doc/en/announce/index.rst | 1 + doc/en/announce/release-5.3.5.rst | 19 +++++++++++++++++++ doc/en/changelog.rst | 9 +++++++++ doc/en/example/parametrize.rst | 7 ++----- doc/en/example/reportingdemo.rst | 4 ++-- doc/en/example/simple.rst | 2 +- doc/en/getting-started.rst | 2 +- 7 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 doc/en/announce/release-5.3.5.rst diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index fb17b8e93..a35039587 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-5.3.5 release-5.3.4 release-5.3.3 release-5.3.2 diff --git a/doc/en/announce/release-5.3.5.rst b/doc/en/announce/release-5.3.5.rst new file mode 100644 index 000000000..46095339f --- /dev/null +++ b/doc/en/announce/release-5.3.5.rst @@ -0,0 +1,19 @@ +pytest-5.3.5 +======================================= + +pytest 5.3.5 has just been released to PyPI. + +This is a bug-fix release, being a drop-in replacement. To upgrade:: + + pip install --upgrade pytest + +The full changelog is available at https://docs.pytest.org/en/latest/changelog.html. + +Thanks to all who contributed to this release, among them: + +* Daniel Hahler +* Ran Benita + + +Happy testing, +The pytest Development Team diff --git a/doc/en/changelog.rst b/doc/en/changelog.rst index 0bda6bb54..571661979 100644 --- a/doc/en/changelog.rst +++ b/doc/en/changelog.rst @@ -28,6 +28,15 @@ with advance notice in the **Deprecations** section of releases. .. towncrier release notes start +pytest 5.3.5 (2020-01-29) +========================= + +Bug Fixes +--------- + +- `#6517 `_: Fix regression in pytest 5.3.4 causing an INTERNALERROR due to a wrong assertion. + + pytest 5.3.4 (2020-01-20) ========================= diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index 15593b28a..7201c2a13 100644 --- a/doc/en/example/parametrize.rst +++ b/doc/en/example/parametrize.rst @@ -475,11 +475,8 @@ Running it results in some skips if we don't have all the python interpreters in .. code-block:: pytest . $ pytest -rs -q multipython.py - ssssssssssss...ssssssssssss [100%] - ========================= short test summary info ========================== - SKIPPED [12] $REGENDOC_TMPDIR/CWD/multipython.py:29: 'python3.5' not found - SKIPPED [12] $REGENDOC_TMPDIR/CWD/multipython.py:29: 'python3.7' not found - 3 passed, 24 skipped in 0.12s + ........................... [100%] + 27 passed in 0.12s Indirect parametrization of optional implementations/imports -------------------------------------------------------------------- diff --git a/doc/en/example/reportingdemo.rst b/doc/en/example/reportingdemo.rst index 1c06782f6..eb978c5ea 100644 --- a/doc/en/example/reportingdemo.rst +++ b/doc/en/example/reportingdemo.rst @@ -436,7 +436,7 @@ Here is a nice run of several failures and how ``pytest`` presents things: items = [1, 2, 3] print("items is {!r}".format(items)) > a, b = items.pop() - E TypeError: 'int' object is not iterable + E TypeError: cannot unpack non-iterable int object failure_demo.py:181: TypeError --------------------------- Captured stdout call --------------------------- @@ -516,7 +516,7 @@ Here is a nice run of several failures and how ``pytest`` presents things: def test_z2_type_error(self): items = 3 > a, b = items - E TypeError: 'int' object is not iterable + E TypeError: cannot unpack non-iterable int object failure_demo.py:222: TypeError ______________________ TestMoreErrors.test_startswith ______________________ diff --git a/doc/en/example/simple.rst b/doc/en/example/simple.rst index 1570850fc..05ccbc9b2 100644 --- a/doc/en/example/simple.rst +++ b/doc/en/example/simple.rst @@ -443,7 +443,7 @@ Now we can profile which test functions execute the slowest: ========================= slowest 3 test durations ========================= 0.30s call test_some_are_slow.py::test_funcslow2 0.20s call test_some_are_slow.py::test_funcslow1 - 0.11s call test_some_are_slow.py::test_funcfast + 0.10s call test_some_are_slow.py::test_funcfast ============================ 3 passed in 0.12s ============================= incremental testing - test steps diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index 59197d0d7..f1d26e064 100644 --- a/doc/en/getting-started.rst +++ b/doc/en/getting-started.rst @@ -28,7 +28,7 @@ Install ``pytest`` .. code-block:: bash $ pytest --version - This is pytest version 5.x.y, imported from $PYTHON_PREFIX/lib/python3.6/site-packages/pytest/__init__.py + This is pytest version 5.x.y, imported from $PYTHON_PREFIX/lib/python3.8/site-packages/pytest/__init__.py .. _`simpletest`: