Skip to content

Commit fb99b5c

Browse files
committed
Revert "Fix type errors after adding types to the py dependency"
This reverts commit 930a158. Regression test from Bruno Oliveira.
1 parent ddfa41b commit fb99b5c

File tree

8 files changed

+32
-25
lines changed

8 files changed

+32
-25
lines changed

src/_pytest/config/argparsing.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def parse(self, args, namespace=None):
8282

8383
self.optparser = self._getparser()
8484
try_argcomplete(self.optparser)
85-
strargs = [str(x) if isinstance(x, py.path.local) else x for x in args]
86-
return self.optparser.parse_args(strargs, namespace=namespace)
85+
args = [str(x) if isinstance(x, py.path.local) else x for x in args]
86+
return self.optparser.parse_args(args, namespace=namespace)
8787

8888
def _getparser(self) -> "MyOptionParser":
8989
from _pytest._argcomplete import filescompleter
@@ -124,8 +124,8 @@ def parse_known_and_unknown_args(
124124
the remaining arguments unknown at this point.
125125
"""
126126
optparser = self._getparser()
127-
strargs = [str(x) if isinstance(x, py.path.local) else x for x in args]
128-
return optparser.parse_known_args(strargs, namespace=namespace)
127+
args = [str(x) if isinstance(x, py.path.local) else x for x in args]
128+
return optparser.parse_known_args(args, namespace=namespace)
129129

130130
def addini(self, name, help, type=None, default=None):
131131
""" register an ini-file option.

src/_pytest/config/findpaths.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import os
2-
from typing import Any
3-
from typing import Iterable
42
from typing import List
53
from typing import Optional
6-
from typing import Tuple
74

85
import py
96

@@ -63,7 +60,7 @@ def getcfg(args, config=None):
6360
return None, None, None
6461

6562

66-
def get_common_ancestor(paths: Iterable[py.path.local]) -> py.path.local:
63+
def get_common_ancestor(paths):
6764
common_ancestor = None
6865
for path in paths:
6966
if not path.exists():
@@ -116,7 +113,7 @@ def determine_setup(
116113
args: List[str],
117114
rootdir_cmd_arg: Optional[str] = None,
118115
config: Optional["Config"] = None,
119-
) -> Tuple[py.path.local, Optional[str], Any]:
116+
):
120117
dirs = get_dirs_from_args(args)
121118
if inifile:
122119
iniconfig = py.iniconfig.IniConfig(inifile)

src/_pytest/doctest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def repr_failure(self, excinfo):
308308
else:
309309
return super().repr_failure(excinfo)
310310

311-
def reportinfo(self) -> Tuple[py.path.local, int, str]:
311+
def reportinfo(self) -> Tuple[str, int, str]:
312312
return self.fspath, self.dtest.lineno, "[doctest] %s" % self.name
313313

314314

src/_pytest/fixtures.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def __init__(self, pyfuncitem):
351351
self.fixturename = None
352352
#: Scope string, one of "function", "class", "module", "session"
353353
self.scope = "function"
354-
self._fixture_defs = {} # type: Dict[str, FixtureDef]
354+
self._fixture_defs = {} # argname -> FixtureDef
355355
fixtureinfo = pyfuncitem._fixtureinfo
356356
self._arg2fixturedefs = fixtureinfo.name2fixturedefs.copy()
357357
self._arg2index = {}
@@ -426,8 +426,7 @@ def module(self):
426426
@scopeproperty()
427427
def fspath(self) -> py.path.local:
428428
""" the file system path of the test module which collected this test. """
429-
# TODO: Remove ignore once _pyfuncitem is properly typed.
430-
return self._pyfuncitem.fspath # type: ignore
429+
return self._pyfuncitem.fspath
431430

432431
@property
433432
def keywords(self):
@@ -550,9 +549,7 @@ def _compute_fixture_value(self, fixturedef):
550549
source_lineno = frameinfo.lineno
551550
source_path = py.path.local(source_path)
552551
if source_path.relto(funcitem.config.rootdir):
553-
source_path_str = source_path.relto(funcitem.config.rootdir)
554-
else:
555-
source_path_str = str(source_path)
552+
source_path = source_path.relto(funcitem.config.rootdir)
556553
msg = (
557554
"The requested fixture has no parameter defined for test:\n"
558555
" {}\n\n"
@@ -561,7 +558,7 @@ def _compute_fixture_value(self, fixturedef):
561558
funcitem.nodeid,
562559
fixturedef.argname,
563560
getlocation(fixturedef.func, funcitem.config.rootdir),
564-
source_path_str,
561+
source_path,
565562
source_lineno,
566563
)
567564
)

src/_pytest/main.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ class Failed(Exception):
367367

368368
@attr.s
369369
class _bestrelpath_cache(dict):
370-
path = attr.ib(type=py.path.local)
370+
path = attr.ib()
371371

372-
def __missing__(self, path: py.path.local) -> str:
372+
def __missing__(self, path: str) -> str:
373373
r = self.path.bestrelpath(path) # type: str
374374
self[path] = r
375375
return r
@@ -399,7 +399,7 @@ def __init__(self, config):
399399
self._node_cache = {}
400400
self._bestrelpathcache = _bestrelpath_cache(
401401
config.rootdir
402-
) # type: Dict[py.path.local, str]
402+
) # type: Dict[str, str]
403403
# Dirnames of pkgs with dunder-init files.
404404
self._pkg_roots = {}
405405

@@ -414,7 +414,7 @@ def __repr__(self):
414414
self.testscollected,
415415
)
416416

417-
def _node_location_to_relpath(self, node_path: py.path.local) -> str:
417+
def _node_location_to_relpath(self, node_path: str) -> str:
418418
# bestrelpath is a quite slow function
419419
return self._bestrelpathcache[node_path]
420420

src/_pytest/nodes.py

-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ def reportinfo(self) -> Tuple[Union[py.path.local, str], Optional[int], str]:
462462
@cached_property
463463
def location(self) -> Tuple[str, Optional[int], str]:
464464
location = self.reportinfo()
465-
assert isinstance(location[0], py.path.local), location[0]
466465
fspath = self.session._node_location_to_relpath(location[0])
467466
assert type(location[2]) is str
468467
return (fspath, location[1], location[2])

testing/python/collect.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1018,18 +1018,18 @@ class TestReportInfo:
10181018
def test_itemreport_reportinfo(self, testdir):
10191019
testdir.makeconftest(
10201020
"""
1021-
import pytest, py
1021+
import pytest
10221022
class MyFunction(pytest.Function):
10231023
def reportinfo(self):
1024-
return py.path.local("foo"), 42, "custom"
1024+
return "ABCDE", 42, "custom"
10251025
def pytest_pycollect_makeitem(collector, name, obj):
10261026
if name == "test_func":
10271027
return MyFunction(name, parent=collector)
10281028
"""
10291029
)
10301030
item = testdir.getitem("def test_func(): pass")
10311031
item.config.pluginmanager.getplugin("runner")
1032-
assert item.location == ("foo", 42, "custom")
1032+
assert item.location == ("ABCDE", 42, "custom")
10331033

10341034
def test_func_reportinfo(self, testdir):
10351035
item = testdir.getitem("def test_func(): pass")

testing/test_nose.py

+14
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,17 @@ def test_io(self):
375375
)
376376
result = testdir.runpytest()
377377
result.stdout.fnmatch_lines(["* 1 skipped *"])
378+
379+
380+
def test_issue_6517(testdir):
381+
testdir.makepyfile(
382+
"""
383+
from nose.tools import raises
384+
385+
@raises(RuntimeError)
386+
def test_fail_without_tcp():
387+
raise RuntimeError
388+
"""
389+
)
390+
result = testdir.runpytest()
391+
result.stdout.fnmatch_lines(["* 1 passed *"])

0 commit comments

Comments
 (0)