Skip to content

Commit f048360

Browse files
committed
Merge test_doubleNestingReportsClosestName
The test_doubleNestingReportsClosestName in test_doctest only differs by the expected line number of the error, which can be dynamically determined using TestCase.withDoctest.
1 parent dcf31a1 commit f048360

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

pyflakes/test/test_doctests.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -376,22 +376,5 @@ def test_futureImportUsed(self):
376376

377377

378378
class TestUndefinedNames(_DoctestMixin, TestUndefinedNames):
379-
380-
def test_doubleNestingReportsClosestName(self):
381-
"""
382-
Lines in doctest are a bit different so we can't use the test
383-
from TestUndefinedNames
384-
"""
385-
exc = self.flakes('''
386-
def a():
387-
x = 1
388-
def b():
389-
x = 2 # line 7 in the file
390-
def c():
391-
x
392-
x = 3
393-
return x
394-
return x
395-
return x
396-
''', m.UndefinedLocal).messages[0]
397-
self.assertEqual(exc.message_args, ('x', 7))
379+
"""Run TestUndefinedNames with each test wrapped in a doctest."""
380+
pass

pyflakes/test/test_undefined_names.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ def c():
309309
return x
310310
return x
311311
''', m.UndefinedLocal).messages[0]
312-
self.assertEqual(exc.message_args, ('x', 5))
312+
313+
# _DoctestMixin.flakes adds two lines preceding the code above.
314+
expected_line_num = 7 if self.withDoctest else 5
315+
316+
self.assertEqual(exc.message_args, ('x', expected_line_num))
313317

314318
def test_laterRedefinedGlobalFromNestedScope3(self):
315319
"""

0 commit comments

Comments
 (0)