Skip to content

Proposal: Verbose output from tests through decorators. #1792

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

Closed
kdexd opened this issue Aug 5, 2016 · 7 comments
Closed

Proposal: Verbose output from tests through decorators. #1792

kdexd opened this issue Aug 5, 2016 · 7 comments

Comments

@kdexd
Copy link

kdexd commented Aug 5, 2016

Sometimes there are thousands of tests which may print too much on stdout or stderr. In that case, we need verbose output from ten of the tests. To facilitate this, we may introduce a marker for not capturing the output for certain tests.

Final mechanism can be as follows:

def test_foo():
    foo()
    print "foo called"

@pytest.mark.verbose
def test_bar():
    bar()
    print "bar called"
  • Captured outputs can roughly be depicted as:

  • py.test

    bar called

  • py.test --capture=no

    foo called
    bar called

  • It may be taken up a step further to have verbose output from a module / directory recursion through pytest.ini support.

@kdexd
Copy link
Author

kdexd commented Aug 5, 2016

Another alternative is:

  1. py.test (Everything captured)
  2. py.test --capture=some (Marked tests will not be captured)
  3. py.test --capture=no (All tests will not be captured)

@nicoddemus
Copy link
Member

Just FYI in pytest-3.0 capsys and capfd have a disabled() context manager method which disables capturing in the block:

def test_bar(capsys):
    with capsys.disabled():
        bar()
        print "bar called"

@kdexd
Copy link
Author

kdexd commented Aug 5, 2016

Thanks 😄 I am on 2.9 yet and was not aware about it ! Let's see where this discussion heads over, meanwhile I'll upgrade pytest and use this fixture.

@nicoddemus
Copy link
Member

nicoddemus commented Aug 5, 2016

3.0 is not out yet (will be out probably next week), sorry for not being clearer.

Also, I think your proposal is independent from the disabled() context manager and could be implemented as an alternative. 😁

@kdexd
Copy link
Author

kdexd commented Aug 5, 2016

Awesome 😃

@The-Compiler
Copy link
Member

I'm not sure if it's worth having yet another way™ to disable capturing in the core 😉

I guess if someone wants a marker like this, it'd probably be some 5-line hook in conftest.py to do it using capsys.disabled()?

@kdexd
Copy link
Author

kdexd commented Dec 13, 2016

Pytest 3 has been released and I have the feature what I wished to. Thanks, closing this. 😄

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

No branches or pull requests

3 participants