GithubHelp home page GithubHelp logo

pytest-dev / pytest-faulthandler Goto Github PK

View Code? Open in Web Editor NEW
27.0 27.0 13.0 52 KB

py.test plugin that activates the fault handler module during testing

License: MIT License

Python 100.00%
debugging pytest

pytest-faulthandler's People

Contributors

jayvdb avatar lazka avatar mhils avatar nicoddemus avatar njsmith avatar the-compiler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytest-faulthandler's Issues

Seems to break with pytest 3.2

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

use pytest_exception_interact hook

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.

Troubles with setuptools_scm

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?

Add support for dumping stack after a timeout

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:

  • Add an argument --faulthandler-timeout 60 or so - the traceback will be dumped after that many seconds.
  • Before each test, call faulthandler.dump_traceback_later(timeout)
  • After each test, call faulthandler.cancel_dump_traceback_later()

What do you think?

Stop timeout when debugger is invoked

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.

Expose faulthandler.register

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! ๐Ÿ˜„

Feature Request: Defining timeout via pytest.ini variable

Hey, thank you for this lightweight package! In the following, I'd like to suggest a small feature.

Suggestion

Add a faulthandler-timeout variable to the pytest.ini parser.

Explanation

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.

pytest --faulthandler-timeout does not work with pytest 5.0.0

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 :)

'ChannelFileWrite' object has no attribute 'fileno'

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? ๐Ÿ˜ƒ

--faulthandler-timeout on Windows/Py27 CI runs blows up

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.

PyPy support

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.

Handling --faulthandler-timeout on a mixed OS CI

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.