Skip to content

Commit

Permalink
Fix test_comments() in test_source
Browse files Browse the repository at this point in the history
Copied the test as fixed in pytest's repo.
  • Loading branch information
nicoddemus committed Dec 11, 2020
1 parent fef9a32 commit 1affd9c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions testing/code/test_source.py
Expand Up @@ -497,7 +497,7 @@ def test_oneline_and_comment():
source = getstatement(0, "raise ValueError\n#hello")
assert str(source) == "raise ValueError"

def test_comments():
def test_comments() -> None:
source = '''def test():
"comment 1"
x = 1
Expand All @@ -510,11 +510,17 @@ def test_comments():
comment 4
"""
'''
for line in range(2,6):
assert str(getstatement(line, source)) == ' x = 1'
for line in range(6,10):
assert str(getstatement(line, source)) == ' assert False'
assert str(getstatement(10, source)) == '"""'
for line in range(2, 6):
assert str(getstatement(line, source)) == " x = 1"
if sys.version_info >= (3, 8) or hasattr(sys, "pypy_version_info"):
tqs_start = 8
else:
tqs_start = 10
assert str(getstatement(10, source)) == '"""'
for line in range(6, tqs_start):
assert str(getstatement(line, source)) == " assert False"
for line in range(tqs_start, 10):
assert str(getstatement(line, source)) == '"""\ncomment 4\n"""'

def test_comment_in_statement():
source = '''test(foo=1,
Expand Down

0 comments on commit 1affd9c

Please sign in to comment.