Skip to content

Commit 2bb1514

Browse files
Fix incompatibilities with newer dependencies (#201)
This commit fixes an incompatibility with pytest 8.1.1, and some with python 3.12. This commit also fixes up some pycodestyle and pylint problems that snuck in with some earlier commits. Fixes #199 and #198 --------- Co-authored-by: Jonathan Karlsen <JONAK@equinor.com>
1 parent b61e722 commit 2bb1514

File tree

7 files changed

+51
-30
lines changed

7 files changed

+51
-30
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,4 @@ int-import-graph=
258258

259259
# Exceptions that will emit a warning when being caught. Defaults to
260260
# "Exception"
261-
overgeneral-exceptions=Exception
261+
overgeneral-exceptions=builtins.Exception

flaky/flaky_pytest_plugin.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,23 @@ def call_and_report(self, item, when, log=True, **kwds):
130130
:type log:
131131
`bool`
132132
"""
133-
call = runner.call_runtest_hook(item, when, **kwds)
133+
def _call_runtest_hook(item, when, **kwds):
134+
if when == "setup":
135+
ihook = item.ihook.pytest_runtest_setup
136+
elif when == "call":
137+
ihook = item.ihook.pytest_runtest_call
138+
elif when == "teardown":
139+
ihook = item.ihook.pytest_runtest_teardown
140+
else:
141+
assert False, f"Unhandled runtest hook case: {when}"
142+
reraise = (runner.Exit,)
143+
if not item.config.getoption("usepdb", False):
144+
reraise += (KeyboardInterrupt,)
145+
return runner.CallInfo.from_call(
146+
lambda: ihook(item=item, **kwds), when=when, reraise=reraise
147+
)
148+
149+
call = _call_runtest_hook(item, when, **kwds)
134150
self._call_infos[item][when] = call
135151
hook = item.ihook
136152
report = hook.pytest_runtest_makereport(item=item, call=call)

test/test_flaky_decorator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ def test_something():
3838
}
3939

4040
self.assertIsNotNone(flaky_attribute)
41-
self.assertDictContainsSubset(
41+
self.assertLessEqual(
4242
{
4343
FlakyNames.MIN_PASSES: min_passes,
4444
FlakyNames.MAX_RUNS: max_runs,
4545
FlakyNames.CURRENT_PASSES: 0,
4646
FlakyNames.CURRENT_RUNS: 0,
4747
FlakyNames.CURRENT_ERRORS: None
48-
},
49-
flaky_attribute
48+
}.items(),
49+
flaky_attribute.items()
5050
)

test/test_flaky_plugin.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
from flaky._flaky_plugin import _FlakyPlugin
66
from flaky.names import FlakyNames
77

8-
TestCaseDataset = namedtuple("TestCaseDataset",
9-
['max_runs', 'min_passes', 'current_runs', 'current_passes', 'expect_fail'])
8+
TestCaseDataset = namedtuple(
9+
"TestCaseDataset",
10+
['max_runs', 'min_passes', 'current_runs', 'current_passes', 'expect_fail'],
11+
)
12+
1013

1114
class TestFlakyPlugin(TestCase):
12-
_test_dataset = (
15+
_test_dataset = {
1316
"default_not_started": TestCaseDataset(2, 1, 0, 0, False),
1417
"default_one_failure": TestCaseDataset(2, 1, 1, 0, False),
1518
"default_one_success": TestCaseDataset(2, 1, 1, 1, False),
@@ -21,10 +24,10 @@ class TestFlakyPlugin(TestCase):
2124
"three_two_two_failures": TestCaseDataset(3, 2, 2, 0, True),
2225
"three_two_one_failure_one_success": TestCaseDataset(3, 2, 2, 1, False),
2326
"three_two_two_successes": TestCaseDataset(3, 2, 2, 2, False),
24-
)
27+
}
2528

2629
def setUp(self):
27-
super(TestFlakyPlugin, self).setUp()
30+
super().setUp()
2831
self._flaky_plugin = _FlakyPlugin()
2932

3033
def test_flaky_plugin_handles_non_ascii_byte_string_in_exception(self):
@@ -39,18 +42,18 @@ def test_flaky_plugin_handles_non_ascii_byte_string_in_exception(self):
3942
)
4043

4144
def test_flaky_plugin_identifies_failure(self):
42-
for test in _test_dataset:
43-
with self.subTest(test):
45+
for name, test in self._test_dataset:
46+
with self.subTest(name):
4447
flaky = {
45-
FlakyNames.CURRENT_PASSES: _test_dataset[test].current_passes,
46-
FlakyNames.CURRENT_RUNS: _test_dataset[test].current_runs,
47-
FlakyNames.MAX_RUNS: _test_dataset[test].max_runs,
48-
FlakyNames.MIN_PASSES: _test_dataset[test].min_passes,
48+
FlakyNames.CURRENT_PASSES: test.current_passes,
49+
FlakyNames.CURRENT_RUNS: test.current_runs,
50+
FlakyNames.MAX_RUNS: test.max_runs,
51+
FlakyNames.MIN_PASSES: test.min_passes,
4952
}
5053
# pylint:disable=protected-access
5154
self.assertEqual(
5255
self._flaky_plugin._has_flaky_test_failed(flaky),
53-
_test_dataset[test].expect_fail,
56+
test.expect_fail,
5457
)
5558

5659
def test_write_unicode_to_stream(self):

test/test_multiprocess_string_io.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class TestMultiprocessStringIO(TestCase):
66
_unicode_string = 'Plain Hello'
77
_unicode_string_non_ascii = 'ńőń ȁŝćȉȉ ŝƭȕƒƒ'
88
_test_values = {
9-
"no_writes": ([], ''),
10-
"one_write": ([_unicode_string], _unicode_string),
11-
"two_writes": (
12-
[_unicode_string, _unicode_string_non_ascii],
13-
'{}{}'.format(_unicode_string, _unicode_string_non_ascii),
14-
)
9+
"no_writes": ([], ''),
10+
"one_write": ([_unicode_string], _unicode_string),
11+
"two_writes": (
12+
[_unicode_string, _unicode_string_non_ascii],
13+
'{}{}'.format(_unicode_string, _unicode_string_non_ascii),
14+
),
1515
}
1616

1717
def setUp(self):
@@ -23,16 +23,16 @@ def setUp(self):
2323
self._string_ios = (self._string_io, self._mp_string_io)
2424

2525
def test_write_then_read(self):
26-
for name in _test_values:
26+
for name, value in self._test_values.items():
2727
with self.subTest(name):
2828
for string_io in self._string_ios:
29-
for item in _test_values[name][0]:
29+
for item in value[0]:
3030
string_io.write(item)
31-
self.assertEqual(string_io.getvalue(), _test_values[name][1])
31+
self.assertEqual(string_io.getvalue(), value[1])
3232

3333
def test_writelines_then_read(self):
34-
for name in _test_values:
34+
for name, value in self._test_values.items():
3535
with self.subTest(name):
3636
for string_io in self._string_ios:
37-
string_io.writelines(_test_values[name][0])
38-
self.assertEqual(string_io.getvalue(), _test_values[name][1])
37+
string_io.writelines(value[0])
38+
self.assertEqual(string_io.getvalue(), value[1])

test/test_pytest/test_flaky_pytest_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def error_raising_setup_function(item):
239239
flaky_test.ihook = Mock()
240240
flaky_test.ihook.pytest_runtest_setup = error_raising_setup_function
241241
flaky_plugin._call_infos[flaky_test] = {} # pylint:disable=protected-access
242-
call_info = runner.call_runtest_hook(flaky_test, 'setup')
242+
call_info = runner.CallInfo.from_call(lambda: flaky_test.ihook.pytest_runtest_setup(flaky_test), when='setup')
243243
assert flaky_test.ran_setup
244244
assert string_io.getvalue() == mock_io.getvalue()
245245
assert call_info.excinfo.type is ZeroDivisionError

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ envlist =
44
py39,
55
py310,
66
py311,
7+
py312,
78
pypy310,
89
pycodestyle,
910
pylint,
@@ -31,6 +32,7 @@ commands =
3132

3233
[testenv:coverage]
3334
commands =
35+
pip install setuptools
3436
python setup.py develop
3537
pytest -k 'example and not options' --doctest-modules --no-flaky-report --cov flaky --cov-report term-missing test/test_pytest/
3638
pytest -p no:flaky --cov flaky --cov-report term-missing test/test_pytest/test_flaky_pytest_plugin.py

0 commit comments

Comments
 (0)