qtbot fails in github actions if cv2 is imported
See original GitHub issueWhat I encountered
I imported cv2
module in my testing file, and github action fails with similar error in #293 .
However, when I lazy-import cv2
by loading it inside function block, the error disappears.
Reproducing the error
I made a repository to reproduce this error : https://github.com/JSS95/pytestqt-githubaction
In commit 976f3af, I imported cv2
in function block and the test does not fail.
In commit f23f189, I imported cv2
at the top of the file and the test fails.
My environment
I am using PyQt5
with pytest-qt
. My CI ran on ubuntu, Python 3.7.
I followed the troubleshooting guide in the document, and all was well before I import cv2.
Error log
============================= test session starts ==============================
platform linux -- Python 3.7.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
PyQt5 5.15.6 -- Qt runtime 5.15.2 -- Qt compiled 5.15.2
rootdir: /home/runner/work/pytestqt-githubaction/pytestqt-githubaction
plugins: xvfb-2.0.0, qt-4.0.2
collected 1 item
Fatal Python error: Aborted
Current thread 0x00007fb4a1414740 (most recent call first):
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytestqt/plugin.py", line 41 in qapp
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/fixtures.py", line 932 in call_fixture_func
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/fixtures.py", line 1126 in pytest_fixture_setup
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/fixtures.py", line 1072 in execute
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/fixtures.py", line 687 in _compute_fixture_value
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/fixtures.py", line 601 in _get_active_fixturedef
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/fixtures.py", line 581 in getfixturevalue
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/fixtures.py", line 568 in _fillfixtures
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/python.py", line 1647 in setup
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py", line 449 in prepare
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py", line 150 in pytest_runtest_setup
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py", line 255 in <lambda>
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py", line 311 in from_call
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py", line 255 in call_runtest_hook
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py", line 215 in call_and_report
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py", line 120 in runtestprotocol
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py", line 109 in pytest_runtest_protocol
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/main.py", line 348 in pytest_runtestloop
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/main.py", line 323 in _main
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/main.py", line 269 in wrap_session
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/main.py", line 316 in pytest_cmdline_main
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/config/__init__.py", line 163 in main
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/config/__init__.py", line 185 in console_main
File "/opt/hostedtoolcache/Python/3.7.12/x64/bin/pytest", line 8 in <module>
/home/runner/work/_temp/035e6ce0-402d-47c0-9d15-d62f155e6d0d.sh: line 1: 1728 Aborted (core dumped) pytest
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
qtbot with PySide2 fails in github actions · Issue #293
hi, Hi the following bug in github actions CI not locally: ... qtbot fails in github actions if cv2 is imported #396.
Read more >Importing cv2 prevents matplotlib from working #386 - GitHub
here is an example of the code : import matplotlib import matplotlib.pyplot as plt import cv2 plt.plot(range(5)) plt.show().
Read more >Sign up - GitHub
But during testing on single image i am getting error during show which is ... qtbot fails in github actions if cv2 is...
Read more >Qt Error on cv2.imshow - Specific to version 4.2.0.32 #290
I am suggesting that we do it automatically when the cv2 module is imported so that users don't have to do it themselves....
Read more >pytest-qt Documentation
you can use opencv-python-headless instead of full opencv-python. More details can be found in issue #396. 12.3. GitHub Actions.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks. I found https://github.com/opencv/opencv-python/issues/386, and using
opencv-python-headless
module resolved this error.For anyone that might encounter same issue:
pytest-xvfb
resolves this.opencv-python-headless
, which has no binding to Qt, can fix this.If you still want to use
python-opencv
and notopencv-python-headless
then a workaround is: