pytest-dev / pytest-faulthandler Goto Github PK
View Code? Open in Web Editor NEWpy.test plugin that activates the fault handler module during testing
License: MIT License
py.test plugin that activates the fault handler module during testing
License: MIT License
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/jenkins/Work/miniconda/envs/_ben10-linux64-py27/lib/python2.7/site-packages/_pytest/main.py", line 106, in wrap_session
INTERNALERROR> config._do_configure()
INTERNALERROR> File "/home/jenkins/Work/miniconda/envs/_ben10-linux64-py27/lib/python2.7/site-packages/_pytest/config.py", line 923, in _do_configure
INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> File "/home/jenkins/Work/miniconda/envs/_ben10-linux64-py27/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 750, in call_historic
INTERNALERROR> self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/home/jenkins/Work/miniconda/envs/_ben10-linux64-py27/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/jenkins/Work/miniconda/envs/_ben10-linux64-py27/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/home/jenkins/Work/miniconda/envs/_ben10-linux64-py27/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/jenkins/Work/miniconda/envs/_ben10-linux64-py27/lib/python2.7/site-packages/pytest_faulthandler.py", line 24, in pytest_configure
INTERNALERROR> stderr_fd_copy = os.dup(sys.stderr.fileno())
INTERNALERROR> UnsupportedOperation: fileno
pytest-timeout also uses this hook:
@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(node):
timeout_teardown(node)
I imagine pytest-faulthandler would want to cancel it's timeout as well for this hook.
Hello.
Because pytest-faulthandler uses setuptools_scm to determine package version, it's impossible to build pytest-faulthandler from source tarball downloaded from Github or PyPI.
All tries end with this error:
LookupError: setuptools-scm was unable to detect version for '/home/lbalhar/Packages/python-pytest-faulthandler/pytest-faulthandler-1.5.0'.
If I understand how setuptools_scm works, it needs .git
folder or PKG-INFO
file to determine package version but tarballs from Github and PyPI don't contain these metadata.
It's obvious why .git
folder isn't part of mentioned tarballs but it's strange why PyPI tarball doesn't contain PKG-INFO
file when it's created automatically by python setup.py sdist
(tested). Are you using this command to create a source tarball for PyPI?
I don't know if it's a good idea to add PKG-INFO
file directly to this project but pytest, for example, has one. Probably simplest solution here is to recreate PyPI tarball with sdist command and check whether it contains PKG-INFO
file.
What do you think about it?
I currently have a test which hangs on Windows sometimes, and I have no idea why - so I thought about adding something to pytest-faulthandler which essentially does this:
--faulthandler-timeout 60
or so - the traceback will be dumped after that many seconds.faulthandler.dump_traceback_later(timeout)
faulthandler.cancel_dump_traceback_later()
What do you think?
Crashes might happen during garbage collection of objects, well past the point pytest_unconfigure
was called and pytest has even returned control to __main__
.
When having a import pdb; pdb.set_trace()
somewhere to debug something, the timeout still continues to run.
If pytest exposes hooks for that (I didn't check yet), I think the timeout should be stopped there.
faulthandler.register is quite useful (and also doesn't exist on Windows, unfortunately) - it allows a user to send a signal to the process to show the traceback.
I think it should be exposed by pytest-faulthandler
as well, with a --faulthandler-signal=SIGUSR1
argument (for example).
It then does getattr(signal, faulthandler_signal)
and getattr(signal, 'SIG' + faulthandler_signal)
(with signal
being the signal module) to find out which signal the user meant. The second variant is useful as leaving off the SIG
is an usual thing to do (e.g. when using kill
, that works as well).
Then it calls faulthandler.register
to register output to the duplicated stdout and faulthandler.unregister
when cleaning up.
I can work on this at some point in the future, but if you feel like, please go ahead! ๐
Hey, thank you for this lightweight package! In the following, I'd like to suggest a small feature.
Add a faulthandler-timeout variable to the pytest.ini parser.
Currently, it seems as if it is not possible to specify a faulthandler timeout in a pytest.ini file in a way that it also works without having pytest-faulthandler installed. With a custom variable, this should be trivial.
Note that something similar to this suggestion is already implemented by pytest-timeout, so that might give a good blueprint.
After pytest-faulthandler
was integrated into the core of pytest 5.0.0 only the ini-option faulthandler_timeout
is available, but this shadows the usage of faulthandler-timeout
:
โฏ python -m pytest --faulthandler_timeout=10
/Users/pgalindo3/.local/share/virtualenvs/venv-TdjqqweH/lib/python3.7/site-packages/_pytest/config/__init__.py:297: PytestConfigWarning: pytest-faulthandler plugin has been merged into the core, please remove it from your requirements.
name.replace("_", "-")
ERROR: usage: pytest.py [options] [file_or_dir] [file_or_dir] [...]
pytest.py: error: unrecognized arguments: --faulthandler_timeout=10
inifile: /Users/pgalindo/github/venv/tox.ini
rootdir: /Users/pgalindo/github/venv
If this should be an issue on https://github.com/pytest-dev/pytest I can close this and reopen one ther e :)
Hi,
I'm running into issues when having both pytest-faulthandler and python-xdist installed:
(venv) C:\Users\user\git\mitmproxy>py.test -f
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "c:\users\user\git\mitmproxy\venv\lib\site-packages\_pytest\main.py", line 92, in wrap_session
INTERNALERROR> config._do_configure()
INTERNALERROR> File "c:\users\user\git\mitmproxy\venv\lib\site-packages\_pytest\config.py", line 859, in _do_configure
INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> File "c:\users\user\git\mitmproxy\venv\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 750, in call_historic
INTERNALERROR> self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "c:\users\user\git\mitmproxy\venv\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "c:\users\user\git\mitmproxy\venv\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "c:\users\user\git\mitmproxy\venv\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 614, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\users\user\git\mitmproxy\venv\lib\site-packages\pytest_faulthandler.py", line 23, in pytest_configure
INTERNALERROR> stderr_fd_copy = os.dup(sys.stderr.fileno())
INTERNALERROR> AttributeError: 'ChannelFileWrite' object has no attribute 'fileno'
############################# waiting for changes #############################
### Watching: C:\Users\user\git\mitmproxy
(venv) C:\Users\user\git\mitmproxy>pip uninstall pytest-faulthandler
[...]
(venv) C:\Users\user\git\mitmproxy>py.test -f
============================= test session starts =============================
platform win32 -- Python 3.5.2, pytest-3.0.3, py-1.4.31, pluggy-0.4.0
rootdir: C:\Users\user\git\mitmproxy, inifile: setup.cfg
plugins: xdist-1.15.0, timeout-1.0.0, cov-2.4.0
Any hints on how this can be fixed? ๐
Maybe link to https://docs.pytest.org/en/stable/usage.html#fault-handler instead? It's currently hard to find the proper pointers w/o googling.
Issue seems to be identical to #8, was thinking . about commenting there but given that was 4 years ago, I thought I would open my own issue.
On azure-pipelines I . call pytest in the following fashion
python -m pytest -sv \
--junitxml=junit/test-results.xml \
--cov pyqtgraph --cov-report=xml --cov-report=html \
--faulthandler-timeout=60
When I make this call on my Windows/Python2.7 runs I get the following error:
========================== Starting Command Output ===========================
[command]"C:\Program Files\Git\bin\bash.exe" --noprofile --norc /d/a/_temp/a5488e34-446c-41fb-9365-433e149de497.sh
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "C:\Miniconda\envs\test-environment-2.7\lib\site-packages\_pytest\main.py", line 201, in wrap_session
INTERNALERROR> config._do_configure()
INTERNALERROR> File "C:\Miniconda\envs\test-environment-2.7\lib\site-packages\_pytest\config\__init__.py", line 668, in _do_configure
INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> File "C:\Miniconda\envs\test-environment-2.7\lib\site-packages\pluggy\hooks.py", line 311, in call_historic
INTERNALERROR> res = self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "C:\Miniconda\envs\test-environment-2.7\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "C:\Miniconda\envs\test-environment-2.7\lib\site-packages\pluggy\manager.py", line 81, in <lambda>
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "C:\Miniconda\envs\test-environment-2.7\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "C:\Miniconda\envs\test-environment-2.7\lib\site-packages\pluggy\callers.py", line 81, in get_result
INTERNALERROR> _reraise(*ex) # noqa
INTERNALERROR> File "C:\Miniconda\envs\test-environment-2.7\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "C:\Miniconda\envs\test-environment-2.7\lib\site-packages\pytest_faulthandler.py", line 40, in pytest_configure
INTERNALERROR> config.warn(code='C1', message=message)
INTERNALERROR> AttributeError: 'Config' object has no attribute 'warn'
##[error]Bash exited with code '3'.
For all the other python/OS configurations besides PyQt4/PySide1 - Windows - Python2.7 it runs just fine.
Installation with pip currently fails because PyPy has faulthandler included:
Processing /home/lazka/Desktop/xxx/pytest-faulthandler
Requirement already satisfied: pytest>=2.6 in /home/lazka/Desktop/pypyvenv/site-packages (from pytest-faulthandler==1.4.2.dev1+g3c4eec3)
Collecting faulthandler (from pytest-faulthandler==1.4.2.dev1+g3c4eec3)
Using cached https://files.pythonhosted.org/packages/ce/8b/24cfaae65452373863a3dd6e45db7767024b5b03bd44bafc079c7de202fc/faulthandler-3.0.tar.gz
Complete output from command python setup.py egg_info:
ERROR: faulthandler is written for CPython, it doesn't work on PyPy
faulthandler builtin PyPy since PyPy 5.5: use pypy -X faulthandler
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-xXctbf/faulthandler/
It would be nice if it wouldn't require the faulthandler package with pypy.
I just wanted to add --faulthandler-timeout 20
to my tox.ini
, but that broke my tests on Windows as it's not supported there.
What's the best way to solve this? The two things I can think of is adding a --faulthandler-maybe-timeout
or so which gets ignored on Windows (rather than being an error), or adding some hook to my conftest.py
which adds the option if not on Windows (but pytest_cmdline_preparse
which sounded appropriate is deprecated).
What do you think?
Hi,
I think it would be cool if you could release a 2.0 package that is just a dummy package that simply depends on pytest>5.0.
This would help downstream transition to pytest 5.0 without explicitly depending on it.
Thanks!
Mark
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.