Skip to content

Commit 134ab0d

Browse files
committed
Module docstrings in 3.7 are not part of Module node anymore
Fixes pytest-dev#3530
1 parent d609b63 commit 134ab0d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

testing/test_assertrewrite.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ class TestAssertionRewrite(object):
7070
def test_place_initial_imports(self):
7171
s = """'Doc string'\nother = stuff"""
7272
m = rewrite(s)
73-
# Module docstrings in 3.7 are part of Module node, it's not in the body
73+
# Module docstrings in 3.8 are part of Module node, it's not in the body
7474
# so we remove it so the following body items have the same indexes on
7575
# all Python versions
76-
if sys.version_info < (3, 7):
76+
# This was briefly in 3.7 as well but got reverted in beta 5
77+
# TODO:
78+
# We have a complicated sys.version_info if in here to ease testing on
79+
# various Python 3.7 versions, but we should remove the 3.7 check after
80+
# 3.7 is released as stable
81+
if sys.version_info < (3, 8) or
82+
(3, 7) <= sys.version_info <= (3, 7, 0, 'beta', 4):
7783
assert isinstance(m.body[0], ast.Expr)
7884
assert isinstance(m.body[0].value, ast.Str)
7985
del m.body[0]
@@ -92,7 +98,8 @@ def test_place_initial_imports(self):
9298
assert isinstance(m.body[3], ast.Expr)
9399
s = """'doc string'\nfrom __future__ import with_statement"""
94100
m = rewrite(s)
95-
if sys.version_info < (3, 7):
101+
if sys.version_info < (3, 8) or
102+
(3, 7) <= sys.version_info <= (3, 7, 0, 'beta', 4):
96103
assert isinstance(m.body[0], ast.Expr)
97104
assert isinstance(m.body[0].value, ast.Str)
98105
del m.body[0]
@@ -103,7 +110,8 @@ def test_place_initial_imports(self):
103110
assert imp.col_offset == 0
104111
s = """'doc string'\nfrom __future__ import with_statement\nother"""
105112
m = rewrite(s)
106-
if sys.version_info < (3, 7):
113+
if sys.version_info < (3, 8) or
114+
(3, 7) <= sys.version_info <= (3, 7, 0, 'beta', 4):
107115
assert isinstance(m.body[0], ast.Expr)
108116
assert isinstance(m.body[0].value, ast.Str)
109117
del m.body[0]
@@ -124,7 +132,8 @@ def test_place_initial_imports(self):
124132
def test_dont_rewrite(self):
125133
s = """'PYTEST_DONT_REWRITE'\nassert 14"""
126134
m = rewrite(s)
127-
if sys.version_info < (3, 7):
135+
if sys.version_info < (3, 8) or
136+
(3, 7) <= sys.version_info <= (3, 7, 0, 'beta', 4):
128137
assert len(m.body) == 2
129138
assert isinstance(m.body[0], ast.Expr)
130139
assert isinstance(m.body[0].value, ast.Str)

0 commit comments

Comments
 (0)