-
-
Notifications
You must be signed in to change notification settings - Fork 474
Description
Describe the bug
running unittest with coverage > 7.6.1 fails with pypy 3.10 for some tests. It works with coverage 7.6.1 and below
To Reproduce
-
What version of Python are you using?
-> pypy 3.10
Python: 3.10.14 (39dc8d3c85a7, Aug 27 2024, 14:32:27)
[PyPy 7.3.17 with GCC 10.2.1 20210130 (Red Hat 10.2.1-11)] -
What version of coverage.py shows the problem?
-> 7.6.2 - 7.6.9 -
What versions of what packages do you have installed?
-> see https://github.com/wikimedia/pywikibot/actions/runs/12211147365/job/34068904767 for example -
What code shows the problem?
-> The specific test failing is this:
@patch('builtins.import', side_effect=ImportError, autospec=True)
class TestNoBeautifulSoup(TestCase):
"""Test functions when BeautifulSoup is not installed."""
net = False
def test_html_comparator(self, mocked_import):
"""Test html_comparator when bs4 not installed."""
with self.assertRaises(ImportError):
html_comparator('')
self.assertEqual(mocked_import.call_count, 1)
self.assertIn('bs4', mocked_import.call_args[0])
The code can be found here:
https://github.com/wikimedia/pywikibot/blob/master/tests/diff_tests.py
The shown problem is
======================================================================
ERROR: test_html_comparator (tests.diff_tests.TestNoBeautifulSoup)
Test html_comparator when bs4 not installed.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/hostedtoolcache/PyPy/3.10.14/x64/lib/pypy3.10/unittest/mock.py", line 1379, in patched
return func(*newargs, **newkeywargs)
File "/home/runner/work/pywikibot/pywikibot/tests/diff_tests.py", line 96, in test_html_comparator
with self.assertRaises(ImportError):
File "/opt/hostedtoolcache/PyPy/3.10.14/x64/lib/pypy3.10/site-packages/coverage/pytracer.py", line 258, in _trace
cast(set[TLineNo], self.cur_file_data).add(flineno)
File "<string>", line 3, in __import__
File "/opt/hostedtoolcache/PyPy/3.10.14/x64/lib/pypy3.10/unittest/mock.py", line 1114, in __call__
return self._mock_call(*args, **kwargs)
File "/opt/hostedtoolcache/PyPy/3.10.14/x64/lib/pypy3.10/unittest/mock.py", line 1118, in _mock_call
return self._execute_mock_call(*args, **kwargs)
File "/opt/hostedtoolcache/PyPy/3.10.14/x64/lib/pypy3.10/unittest/mock.py", line 1173, in _execute_mock_call
raise effect
ImportError
- What commands should we run to reproduce the problem?
-> coverage run -m unittest discover -vv -p "*_tests.py";
Expected behavior
Test should run like it does with coverage 7.6.1
Additional context
- unit test failing: https://github.com/wikimedia/pywikibot/actions/runs/12211147365/job/34068904767
- pywikibot issue: https://phabricator.wikimedia.org/T380732 (the I. section)
- previous solutions (dependencies): https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1097439