Skip to content

Commit 16546b7

Browse files
committed
Remove some dead code
- I wrote a thing: https://github.com/asottile/dead - wanted to try it out, there's lots of false positives and I didn't look through all the things it pointed out but here's some
1 parent 0da5531 commit 16546b7

13 files changed

+8
-130
lines changed

src/_pytest/_code/code.py

-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
from _pytest.compat import PY35
2424
from _pytest.compat import safe_str
2525

26-
builtin_repr = repr
27-
2826
if _PY3:
2927
from traceback import format_exception_only
3028
else:
@@ -947,8 +945,6 @@ def toterminal(self, tw):
947945

948946

949947
class ReprEntry(TerminalRepr):
950-
localssep = "_ "
951-
952948
def __init__(self, lines, reprfuncargs, reprlocals, filelocrepr, style):
953949
self.lines = lines
954950
self.reprfuncargs = reprfuncargs
@@ -970,7 +966,6 @@ def toterminal(self, tw):
970966
red = line.startswith("E ")
971967
tw.line(line, bold=True, red=red)
972968
if self.reprlocals:
973-
# tw.sep(self.localssep, "Locals")
974969
tw.line("")
975970
self.reprlocals.toterminal(tw)
976971
if self.reprfileloc:

src/_pytest/assertion/rewrite.py

-13
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ def ast_Call(a, b, c):
5151
return ast.Call(a, b, c, None, None)
5252

5353

54-
def ast_Call_helper(func_name, *args, **kwargs):
55-
"""
56-
func_name: str
57-
args: Iterable[ast.expr]
58-
kwargs: Dict[str,ast.expr]
59-
"""
60-
return ast.Call(
61-
ast.Name(func_name, ast.Load()),
62-
list(args),
63-
[ast.keyword(key, val) for key, val in kwargs.items()],
64-
)
65-
66-
6754
class AssertionRewritingHook(object):
6855
"""PEP302 Import hook which rewrites asserts."""
6956

src/_pytest/fixtures.py

-6
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,6 @@ def addfinalizer(self, finalizer):
660660
self._fixturedef.addfinalizer(finalizer)
661661

662662

663-
class ScopeMismatchError(Exception):
664-
""" A fixture function tries to use a different fixture function which
665-
which has a lower scope (e.g. a Session one calls a function one)
666-
"""
667-
668-
669663
scopes = "session package module class function".split()
670664
scopenum_function = scopes.index("function")
671665

src/_pytest/junitxml.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import time
2020

2121
import py
22+
import six
2223

2324
import pytest
2425
from _pytest import nodes
@@ -27,10 +28,6 @@
2728
# Python 2.X and 3.X compatibility
2829
if sys.version_info[0] < 3:
2930
from codecs import open
30-
else:
31-
unichr = chr
32-
unicode = str
33-
long = int
3431

3532

3633
class Junit(py.xml.Namespace):
@@ -45,12 +42,12 @@ class Junit(py.xml.Namespace):
4542
_legal_chars = (0x09, 0x0A, 0x0D)
4643
_legal_ranges = ((0x20, 0x7E), (0x80, 0xD7FF), (0xE000, 0xFFFD), (0x10000, 0x10FFFF))
4744
_legal_xml_re = [
48-
unicode("%s-%s") % (unichr(low), unichr(high))
45+
u"%s-%s" % (six.unichr(low), six.unichr(high))
4946
for (low, high) in _legal_ranges
5047
if low < sys.maxunicode
5148
]
52-
_legal_xml_re = [unichr(x) for x in _legal_chars] + _legal_xml_re
53-
illegal_xml_re = re.compile(unicode("[^%s]") % unicode("").join(_legal_xml_re))
49+
_legal_xml_re = [six.unichr(x) for x in _legal_chars] + _legal_xml_re
50+
illegal_xml_re = re.compile(u"[^%s]" % u"".join(_legal_xml_re))
5451
del _legal_chars
5552
del _legal_ranges
5653
del _legal_xml_re
@@ -62,9 +59,9 @@ def bin_xml_escape(arg):
6259
def repl(matchobj):
6360
i = ord(matchobj.group())
6461
if i <= 0xFF:
65-
return unicode("#x%02X") % i
62+
return u"#x%02X" % i
6663
else:
67-
return unicode("#x%04X") % i
64+
return u"#x%04X" % i
6865

6966
return py.xml.raw(illegal_xml_re.sub(repl, py.xml.escape(arg)))
7067

@@ -194,7 +191,7 @@ def append_failure(self, report):
194191
else:
195192
if hasattr(report.longrepr, "reprcrash"):
196193
message = report.longrepr.reprcrash.message
197-
elif isinstance(report.longrepr, (unicode, str)):
194+
elif isinstance(report.longrepr, six.string_types):
198195
message = report.longrepr
199196
else:
200197
message = str(report.longrepr)

src/_pytest/python.py

-5
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,6 @@ def getmodpath(self, stopatmodule=True, includemodule=False):
283283
s = ".".join(parts)
284284
return s.replace(".[", "[")
285285

286-
def _getfslineno(self):
287-
return getfslineno(self.obj)
288-
289286
def reportinfo(self):
290287
# XXX caching?
291288
obj = self.obj
@@ -1252,7 +1249,6 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr):
12521249
Python test function.
12531250
"""
12541251

1255-
_genid = None
12561252
# disable since functions handle it themselves
12571253
_ALLOW_MARKERS = False
12581254

@@ -1327,7 +1323,6 @@ def _initrequest(self):
13271323
if hasattr(self, "callspec"):
13281324
callspec = self.callspec
13291325
assert not callspec.funcargs
1330-
self._genid = callspec.id
13311326
if hasattr(callspec, "param"):
13321327
self.param = callspec.param
13331328
self._request = fixtures.FixtureRequest(self)

src/_pytest/reports.py

-10
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,6 @@ def __repr__(self):
158158
)
159159

160160

161-
class TeardownErrorReport(BaseReport):
162-
outcome = "failed"
163-
when = "teardown"
164-
165-
def __init__(self, longrepr, **extra):
166-
self.longrepr = longrepr
167-
self.sections = []
168-
self.__dict__.update(extra)
169-
170-
171161
class CollectReport(BaseReport):
172162
def __init__(self, nodeid, outcome, longrepr, result, sections=(), **extra):
173163
self.nodeid = nodeid

src/_pytest/resultlog.py

-24
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,6 @@ def pytest_unconfigure(config):
4747
config.pluginmanager.unregister(resultlog)
4848

4949

50-
def generic_path(item):
51-
chain = item.listchain()
52-
gpath = [chain[0].name]
53-
fspath = chain[0].fspath
54-
fspart = False
55-
for node in chain[1:]:
56-
newfspath = node.fspath
57-
if newfspath == fspath:
58-
if fspart:
59-
gpath.append(":")
60-
fspart = False
61-
else:
62-
gpath.append(".")
63-
else:
64-
gpath.append("/")
65-
fspart = True
66-
name = node.name
67-
if name[0] in "([":
68-
gpath.pop()
69-
gpath.append(name)
70-
fspath = newfspath
71-
return "".join(gpath)
72-
73-
7450
class ResultLog(object):
7551
def __init__(self, config, logfile):
7652
self.config = config

src/_pytest/terminal.py

-9
Original file line numberDiff line numberDiff line change
@@ -841,15 +841,6 @@ def summary_stats(self):
841841
self.write_line(msg, **markup)
842842

843843

844-
def repr_pythonversion(v=None):
845-
if v is None:
846-
v = sys.version_info
847-
try:
848-
return "%s.%s.%s-%s-%s" % v
849-
except (TypeError, ValueError):
850-
return str(v)
851-
852-
853844
def build_summary_stats_line(stats):
854845
keys = ("failed passed skipped deselected xfailed xpassed warnings error").split()
855846
unknown_key_seen = False

testing/python/metafunc.py

-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,6 @@ def pytest_generate_tests(metafunc):
784784
785785
@pytest.fixture
786786
def metafunc(request):
787-
assert request._pyfuncitem._genid == "0"
788787
return request.param
789788
790789
def test_function(metafunc, pytestconfig):

testing/test_resultlog.py

-29
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
import _pytest._code
1010
import pytest
11-
from _pytest.nodes import FSCollector
12-
from _pytest.nodes import Item
13-
from _pytest.nodes import Node
14-
from _pytest.resultlog import generic_path
1511
from _pytest.resultlog import pytest_configure
1612
from _pytest.resultlog import pytest_unconfigure
1713
from _pytest.resultlog import ResultLog
@@ -20,31 +16,6 @@
2016
pytestmark = pytest.mark.filterwarnings("ignore:--result-log is deprecated")
2117

2218

23-
def test_generic_path(testdir):
24-
from _pytest.main import Session
25-
26-
config = testdir.parseconfig()
27-
session = Session(config)
28-
p1 = Node("a", config=config, session=session, nodeid="a")
29-
# assert p1.fspath is None
30-
p2 = Node("B", parent=p1)
31-
p3 = Node("()", parent=p2)
32-
item = Item("c", parent=p3)
33-
34-
res = generic_path(item)
35-
assert res == "a.B().c"
36-
37-
p0 = FSCollector("proj/test", config=config, session=session)
38-
p1 = FSCollector("proj/test/a", parent=p0)
39-
p2 = Node("B", parent=p1)
40-
p3 = Node("()", parent=p2)
41-
p4 = Node("c", parent=p3)
42-
item = Item("[1]", parent=p4)
43-
44-
res = generic_path(item)
45-
assert res == "test/a:B().c[1]"
46-
47-
4819
def test_write_log_entry():
4920
reslog = ResultLog(None, None)
5021
reslog.logfile = py.io.TextIO()

testing/test_runner.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,7 @@ class TestClass(object):
465465
assert res[1].name == "TestClass"
466466

467467

468-
reporttypes = [
469-
reports.BaseReport,
470-
reports.TestReport,
471-
reports.TeardownErrorReport,
472-
reports.CollectReport,
473-
]
468+
reporttypes = [reports.BaseReport, reports.TestReport, reports.CollectReport]
474469

475470

476471
@pytest.mark.parametrize(

testing/test_session.py

-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ def test_4(self):
181181
passed, skipped, failed = reprec.countoutcomes()
182182
assert failed == skipped == 0
183183
assert passed == 7
184-
# also test listnames() here ...
185184

186185
def test_collect_only_with_various_situations(self, testdir):
187186
p = testdir.makepyfile(

testing/test_terminal.py

-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from _pytest.terminal import _plugin_nameversions
1919
from _pytest.terminal import build_summary_stats_line
2020
from _pytest.terminal import getreportopt
21-
from _pytest.terminal import repr_pythonversion
2221
from _pytest.terminal import TerminalReporter
2322

2423
DistInfo = collections.namedtuple("DistInfo", ["project_name", "version"])
@@ -361,16 +360,6 @@ def test_collectonly_more_quiet(self, testdir):
361360
result.stdout.fnmatch_lines(["*test_fun.py: 1*"])
362361

363362

364-
def test_repr_python_version(monkeypatch):
365-
try:
366-
monkeypatch.setattr(sys, "version_info", (2, 5, 1, "final", 0))
367-
assert repr_pythonversion() == "2.5.1-final-0"
368-
sys.version_info = x = (2, 3)
369-
assert repr_pythonversion() == str(x)
370-
finally:
371-
monkeypatch.undo() # do this early as pytest can get confused
372-
373-
374363
class TestFixtureReporting(object):
375364
def test_setup_fixture_error(self, testdir):
376365
testdir.makepyfile(

0 commit comments

Comments
 (0)