syrusakbary / snapshottest

Snapshot Testing utils for Python 📸
MIT License
537 stars 102 forks source link

Segmentation fault in Python 3.7 #103

Open AvnerCohen opened 5 years ago

AvnerCohen commented 5 years ago

Seething this crash, full report in here: https://github.com/pytest-dev/pytest/issues/3672 Once snapshottest is uninstalled (even of not in use, as in the example provided) this does not happen.

Very easy to recreate. Any thoughts? or anything I can provide or test?

$ pytest  --assert=plain moshe.py
=========================================================================================== test session starts ============================================================================================
platform linux -- Python 3.7.4, pytest-5.2.2, py-1.8.0, pluggy-0.13.0
rootdir: /opt/app
plugins: snapshottest-0.5.1
collecting ... Fatal Python error: Segmentation fault

Current thread 0x00007f6e9e135740 (most recent call first):
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 1043 in create_module
  File "<frozen importlib._bootstrap>", line 583 in module_from_spec
  File "<frozen importlib._bootstrap>", line 670 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 967 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 983 in _find_and_load
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1035 in _handle_fromlist
  File "/opt/app/moshe/lib/python3.7/site-packages/lxml/html/__init__.py", line 53 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 728 in exec_module
  File "<frozen importlib._bootstrap>", line 677 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 967 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 983 in _find_and_load
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1035 in _handle_fromlist
  File "/opt/app/moshe.py", line 1 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 728 in exec_module
  File "<frozen importlib._bootstrap>", line 677 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 967 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 983 in _find_and_load
  File "/opt/app/moshe/lib/python3.7/site-packages/py/_path/local.py", line 701 in pyimport
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/python.py", line 501 in _importtestmodule
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/python.py", line 433 in _getobj
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/python.py", line 256 in obj
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/python.py", line 449 in _inject_setup_module_fixture
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/python.py", line 436 in collect
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/runner.py", line 256 in <lambda>
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/runner.py", line 229 in from_call
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/runner.py", line 256 in pytest_make_collect_report
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/manager.py", line 86 in <lambda>
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/manager.py", line 92 in _hookexec
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/runner.py", line 375 in collect_one_node
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/main.py", line 703 in genitems
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/main.py", line 478 in _perform_collect
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/main.py", line 439 in perform_collect
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/main.py", line 246 in pytest_collection
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/manager.py", line 86 in <lambda>
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/manager.py", line 92 in _hookexec
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/main.py", line 236 in _main
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/main.py", line 193 in wrap_session
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/main.py", line 230 in pytest_cmdline_main
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/manager.py", line 86 in <lambda>
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/manager.py", line 92 in _hookexec
  File "/opt/app/moshe/lib/python3.7/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/opt/app/moshe/lib/python3.7/site-packages/_pytest/config/__init__.py", line 90 in main
  File "/opt/app/moshe/bin/pytest", line 8 in <module>
Segmentation fault
AvnerCohen commented 5 years ago

A docker repro - https://github.com/AvnerCohen/repro-pytest-segafault

sabard commented 4 years ago

I am having this same issue using OpenCV. The seg fault happens on import cv2 after calling pytest. Downgrading to snapshottest 0.5.0 fixes the issue for me.

sabard commented 4 years ago

Here is an example of the bug: https://github.com/sabard/snapshottest-cv2-bug

sabard commented 4 years ago

BTW—this only happens on Python 3.7, not 3.8. Unfortunately, we need to use 3.7 for the version of OpenCV we're using.

noahnu commented 4 years ago

From another issue, I think there's a fork of snapshottest which is a bit more up to date. As an alternative, I've been working on my own snapshot library (pytest only) which has addressed all the open issues in this repo. It's also actively developed, if you want to give it a try. We're very much open to community feedback (and contributions): https://github.com/tophat/syrupy.

Migration has been kept simple, no need to change call sites (unless you want to use our more pytest friendly syntax).

paulmelnikow commented 4 years ago

I imagine this must be an upstream issue. Based on reading pytest-dev/pytest#3672, it sounds like it is also not an issue with pytest. Python 3.7 is still being supported, so I'd suggest trying to continue the work done in that issue to isolate the problem, and reporting it upstream with Python itself.