-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Ability to disable capture from within a test #1599
Comments
@nicoddemus The |
It works just fine on methods as well. Could you post an example of what you are seeing? |
ScopeMismatch: You tried to access the 'function' scoped fixture 'capsys' with a 'class' scoped request object, involved factories
lib.macosx-10.6-x86_64-2.7/tardis/tests/integration_tests/test_integration.py:24: def setup(self, request, reference, data_path, capsys)``` |
Ahh sorry I though you meant functions vs methods. 😅 Unfortunately no. We plan to have a new scope for fixtures called "invocation" which would allow this kind of thing (#1794), but unfortunately it had to be pulled off at the last minute because it contained a serious flaw on it. |
@nicoddemus so how can I do this now? is there a way instead of using |
I thought on a workaround: copy pytest's implementation, name it Could you describe in more details why you need that functionality in a |
We are testing data generated with this function: https://github.com/tardis-sn/tardis/blob/master/tardis/tests/integration_tests/test_integration.py#L77 and want to make sure that we see what happens when it runs (it takes a long time to run). |
Oh I see. I can't think of a workaround for that, sorry. |
@nicoddemus thanks for looking into this. Well, can I somehow enable |
Found a solution 😁 class Test:
@pytest.fixture(scope='class')
def setup(self, pytestconfig):
capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')
capmanager.suspendcapture()
print('hello from class')
capmanager.resumecapture()
def test_foo(self, setup):
print('cannot see me')
Caveats: uses internal pytest objects, so this may break in the future. Other than that, is exactly what pytest does internally so it should work fine. |
@nicoddemus thanks - that's the one!! |
Whoever may stumble on this useful technique, please be aware that in the meantime |
|
(This was discussed #167 but got side-tracked)
Proposal to disable capturing from within a test:
Optionally, provide a marker which does the same job:
The text was updated successfully, but these errors were encountered: