@@ -65,15 +65,30 @@ def getmsg(f, extra_ns=None, must_pass=False):
65
65
pytest .fail ("function didn't raise at all" )
66
66
67
67
68
+ def python_version_has_docstring_in_module_node ():
69
+ """Module docstrings in 3.8 are part of Module node.
70
+ This was briefly in 3.7 as well but got reverted in beta 5.
71
+
72
+ TODO:
73
+
74
+ We have a complicated sys.version_info if in here to ease testing on
75
+ various Python 3.7 versions, but we should remove the 3.7 check after
76
+ 3.7 is released as stable to make this check more straightforward.
77
+ """
78
+ return (
79
+ sys .version_info < (3 , 8 ) or (3 , 7 ) <= sys .version_info <= (3 , 7 , 0 , "beta" , 4 )
80
+ )
81
+
82
+
68
83
class TestAssertionRewrite (object ):
69
84
70
85
def test_place_initial_imports (self ):
71
86
s = """'Doc string'\n other = stuff"""
72
87
m = rewrite (s )
73
- # Module docstrings in 3.7 are part of Module node, it's not in the body
74
- # so we remove it so the following body items have the same indexes on
75
- # all Python versions
76
- if sys . version_info < ( 3 , 7 ):
88
+ # Module docstrings in some new Python versions are part of Module node
89
+ # It's not in the body so we remove it so the following body items have
90
+ # the same indexes on all Python versions:
91
+ if python_version_has_docstring_in_module_node ( ):
77
92
assert isinstance (m .body [0 ], ast .Expr )
78
93
assert isinstance (m .body [0 ].value , ast .Str )
79
94
del m .body [0 ]
@@ -92,7 +107,7 @@ def test_place_initial_imports(self):
92
107
assert isinstance (m .body [3 ], ast .Expr )
93
108
s = """'doc string'\n from __future__ import with_statement"""
94
109
m = rewrite (s )
95
- if sys . version_info < ( 3 , 7 ):
110
+ if python_version_has_docstring_in_module_node ( ):
96
111
assert isinstance (m .body [0 ], ast .Expr )
97
112
assert isinstance (m .body [0 ].value , ast .Str )
98
113
del m .body [0 ]
@@ -103,7 +118,7 @@ def test_place_initial_imports(self):
103
118
assert imp .col_offset == 0
104
119
s = """'doc string'\n from __future__ import with_statement\n other"""
105
120
m = rewrite (s )
106
- if sys . version_info < ( 3 , 7 ):
121
+ if python_version_has_docstring_in_module_node ( ):
107
122
assert isinstance (m .body [0 ], ast .Expr )
108
123
assert isinstance (m .body [0 ].value , ast .Str )
109
124
del m .body [0 ]
@@ -124,7 +139,7 @@ def test_place_initial_imports(self):
124
139
def test_dont_rewrite (self ):
125
140
s = """'PYTEST_DONT_REWRITE'\n assert 14"""
126
141
m = rewrite (s )
127
- if sys . version_info < ( 3 , 7 ):
142
+ if python_version_has_docstring_in_module_node ( ):
128
143
assert len (m .body ) == 2
129
144
assert isinstance (m .body [0 ], ast .Expr )
130
145
assert isinstance (m .body [0 ].value , ast .Str )
0 commit comments