-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support of pytest capsys #24
Comments
I'm not the original author, just the current maintainer, so I can't speak with authority about historical reasons for using That said, I can't see how an explicit Can you provide some simple-as-possible example code that demonstrates the problem? |
The simplest example is to use the
The test will fail with the assert not being matched. Specifically with the below
However, if you uninstall
Its possible that there is a small issue with the fixture I can try to raise an issue with the pytest team as well. |
Pytest issue raised pytest-dev/pytest#6676 |
the basic issue is that pytest output redirection has to replace sys.stdout/stderr to do "isolated" redirection taking a alias simply negates that |
@mpounsett A possible solution that came out of the pytest issue is to set I tested this on my issue24 branch I have and all the tox tests passed. https://travis-ci.com/shepherdjay/nagiosplugin/builds/147585561 I can open a pull request if you like; my current branch added a |
I did some digging into the origin of using I think I'd like to both understand why |
@mpounsett there is a time lag difference and aliasing #untested
my_alias = sys.stdout
with redirect_stdout(something_else):
print(..., file=my_alias) # goes to the original stdout
print(..., file=None) # goes to the current sys.stdout aka something_else |
@mpounsett as far as the windows tests - I got this semi working in Travis using python 3.7 as well but both on my Windows 10 machine and Travis several tests fail for permissions issues. These tests fail on the most recent release as well as the build that removes the alias. Not sure if this is helpful or not for you but here are the builds. Issue24 - https://travis-ci.com/shepherdjay/nagiosplugin/builds/147641097 In my config I did specify windows was allowed to fail given that it is still experimental in Travis. |
Sorry, @shepherdjay .. I seem to have let this drop of my radar. If you want to send that PR (without the travis config) I'll apply it. Adding the travis stuff would also be great, but I think that should be a separate PR/issue. |
We basically apply the change from mpounsett/nagiosplugin#24 as a fixture, but only when nagiosplugin's version is old.
We basically apply the change from mpounsett/nagiosplugin#24 as a fixture, but only when nagiosplugin's version is old.
We basically apply the change from mpounsett/nagiosplugin#24 as a fixture, but only when nagiosplugin's version is old.
We basically apply the change from mpounsett/nagiosplugin#24 as a fixture, but only when nagiosplugin's version is old.
We basically apply the change from mpounsett/nagiosplugin#24 as a fixture, but only when nagiosplugin's version is old.
We basically apply the change from mpounsett/nagiosplugin#24 as a fixture, but only when nagiosplugin's version is old.
First off great plugin, we were writing a bunch of our own logic and boiler plate for our nagios style tests and I am considering moving over to this plugin to avoid copy paste errors.
The one issue I've had is converting our tests, our current modules use pytest's capsys fixture. To compare the expected output of a check with test data. Sample from one of these tests below.
What's interesting is none of the pytest fixtures for capturing stdout seem to capture nagiosplugins output. More interesting is that the output does appear in the test results summary like this
test_load.py::test_main FAILED [ 56%]LOAD OK - avg is 2 | avg=2;75;85;0;100 max=10;75;85;0;100
As far as I can tell the reason appears to be related to the
Runtime
classexecute
method where it prints with thefile
keyword argument set toself.stdout
which itself is justsys.stdout
Since writing to stdout is the default behavior of
print
I'm curious if it being explicitly specified is to solve a specific problem or if this can be removed to allow test frameworks like pytest to capture the output?The text was updated successfully, but these errors were encountered: