Repository navigation
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
Activity
tests: use coverage < 7.6.2 with pypy 3.10
nedbat commentedon Dec 7, 2024
When I try to run your command
coverage run -m unittest discover -vv -p "*_tests.py", I get:I see the .sample, and the pwb.py tool, but running them starts asking me questions I don't know the answer to. Please provide complete instructions for me to reproduce the failure.
nedbat commentedon Dec 7, 2024
Trying a little harder to make a user-config.py file, I get:
xqt commentedon Dec 10, 2024
Hi @nedbat: The content of user-config.py file does not care for the test, so you just can rename the given
user-config.py.sampleto run the test. Another way is to set a environment variablePYWIKIBOT_NO_USER_CONFIG=2, see Pywikibot config. The test procedure could be as follows$ git clone https://gerrit.wikimedia.org/g/pywikibot/coreor from github mirror: https://github.com/wikimedia/pywikibot
git submodule update --progress --inituser-config.py.sampletouser-config.pypip install -rrequirements.txtpip install -rdev-requirements.txtpip install --upgrade coveragecoverage run -m unittest -vv tests/diff_tests.pyor possibly alsocoverage run -m unittest discover -vv -p *_tests.pyfor the complete test run but this need a lot of time (30 min) to complete.But be aware: the test fails for pypy3.10 only so you have to install it first and the dependencies is needed for it.
fix: bug #1902
nedbat commentedon Dec 11, 2024
Thanks, those details made it reproducible for me. I have no idea what's going wrong, but
git bisectfound the commit, and reverting the change from that commit to the one line of mine in your stack trace fixed it! I think we really lucked out.nedbat commentedon Dec 11, 2024
This is now fixed in commit 80a479d.
xqt commentedon Dec 11, 2024
Great job, thank you.
nedbat commentedon Dec 26, 2024
This is now released as part of coverage 7.6.10.