Skip to content
This repository was archived by the owner on Jan 20, 2021. It is now read-only.

Don't crash when using pytester in default mode #24

Merged
merged 1 commit into from
Feb 9, 2018

Conversation

njsmith
Copy link
Contributor

@njsmith njsmith commented Feb 9, 2018

If you try to test a pytest plugin using the pytester module, and you
also have pytest-faulthandler installed, then currently it crashes
with obscure errors. The problem is that by default, pytester runs the
sub-pytest in-process, and the sub-pytest has sys.stderr set to a
_pytest.capture.CaptureIO object, which has a fileno method (so the
old hasattr(sys.stderr, "fileno") check passes), but if you try to
call this method then it raises io.UnsupportedOperation.

So this commit robustifies the sys.stderr.fileno() calling code to
handle both a missing fileno (as before), and it raising
UnsupportedOperation.

If you try to test a pytest plugin using the pytester module, and you
also have pytest-faulthandler installed, then currently it crashes
with obscure errors. The problem is that by default, pytester runs the
sub-pytest in-process, and the sub-pytest has sys.stderr set to a
_pytest.capture.CaptureIO object, which has a fileno method (so the
old hasattr(sys.stderr, "fileno") check passes), but if you try to
call this method then it raises io.UnsupportedOperation.

So this commit robustifies the sys.stderr.fileno() calling code to
handle both a missing fileno (as before), and it raising
UnsupportedOperation.
@nicoddemus
Copy link
Member

Thanks @njsmith! I will make a new release shortly!

@nicoddemus nicoddemus merged commit 04391bc into pytest-dev:master Feb 9, 2018
@The-Compiler
Copy link
Member

I've had the same issue, and just ended up passing plugins=['no:faulthandler'] without investigating in detail. This helps indeed! 👍

@The-Compiler
Copy link
Member

Oh, I'm wondering how straightforward it is to add a test for this, though. I guess we could have a subprocess-pytester with the plugin, and from there launch an in-process one?

@njsmith
Copy link
Contributor Author

njsmith commented Feb 9, 2018

@The-Compiler Yeah, I spent a few minutes trying to figure out how to add a test, and then gave up because I couldn't think of one :-). Using pytester inside pytester seems like a workable idea, though!

@njsmith njsmith deleted the dont-crash-with-pytester branch February 9, 2018 10:39
@nicoddemus
Copy link
Member

Indeed a test would be nice.

@njsmith 1.4.1 has been published with this fix, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants