Skip to content

Commit e37bf8c

Browse files
Fix python 3.6 pipeline without deprecation warning (?)
And better comment following review, see #3943 (comment)
1 parent 637597c commit e37bf8c

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

tests/test_func.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,19 @@ def gen_tests(filter_rgx):
135135
gen_tests(FILTER_RGX),
136136
ids=[o[0] for o in gen_tests(FILTER_RGX)],
137137
)
138-
def test_functionality(module_file, messages_file, dependencies):
139-
if module_file in TEST_WITH_EXPECTED_DEPRECATION and sys.version_info.minor > 5:
140-
# Remove <unknown>:x: DeprecationWarning: invalid escape sequence
141-
with pytest.deprecated_call():
142-
__test_functionality(module_file, messages_file, dependencies)
138+
def test_functionality(module_file, messages_file, dependencies, recwarn):
143139
__test_functionality(module_file, messages_file, dependencies)
140+
warning = None
141+
try:
142+
# Catch <unknown>:x: DeprecationWarning: invalid escape sequence
143+
# so it's not shown during tests
144+
warning = recwarn.pop()
145+
except AssertionError:
146+
pass
147+
if warning is not None:
148+
if module_file in TEST_WITH_EXPECTED_DEPRECATION and sys.version_info.minor > 5:
149+
assert issubclass(warning.category, DeprecationWarning)
150+
assert "invalid escape sequence" in str(warning.message)
144151

145152

146153
def __test_functionality(module_file, messages_file, dependencies):

tests/test_functional.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,28 @@ def get_tests():
105105

106106

107107
@pytest.mark.parametrize("test_file", TESTS, ids=TESTS_NAMES)
108-
def test_functional(test_file):
108+
def test_functional(test_file, recwarn):
109109
LintTest = (
110110
LintModuleOutputUpdate(test_file)
111111
if UPDATE.exists()
112112
else testutils.LintModuleTest(test_file)
113113
)
114114
LintTest.setUp()
115-
if test_file.base in TEST_WITH_EXPECTED_DEPRECATION and sys.version_info.minor > 5:
116-
with pytest.deprecated_call():
117-
LintTest._runTest()
118-
else:
119-
LintTest._runTest()
115+
LintTest._runTest()
116+
warning = None
117+
try:
118+
# Catch <unknown>:x: DeprecationWarning: invalid escape sequence
119+
# so it's not shown during tests
120+
warning = recwarn.pop()
121+
except AssertionError:
122+
pass
123+
if warning is not None:
124+
if (
125+
test_file.base in TEST_WITH_EXPECTED_DEPRECATION
126+
and sys.version_info.minor > 5
127+
):
128+
assert issubclass(warning.category, DeprecationWarning)
129+
assert "invalid escape sequence" in str(warning.message)
120130

121131

122132
if __name__ == "__main__":

0 commit comments

Comments
 (0)