Skip to content

basicConfig settings overlap from separate tests #2158

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
r0fls opened this issue Dec 24, 2016 · 1 comment
Closed

basicConfig settings overlap from separate tests #2158

r0fls opened this issue Dec 24, 2016 · 1 comment

Comments

@r0fls
Copy link

r0fls commented Dec 24, 2016

When using logging basicConfig in two tests in the same suite, the settings seem to overlap and interfere with each other.

I'm using pytest version 3.0.4 on Mac OSX Sierra

Here is a minimal example:

Create the following two files:

test_1.py

import logging

logging.basicConfig()
log = logging.getLogger()
def test_foo():
    foo = 1
    log.warn(foo)
    assert foo == 1

test_2.py

from io import StringIO
import logging

log_stream = StringIO()

def test_log():
    logging.basicConfig(stream=log_stream, level=logging.INFO)
    log = logging.getLogger()
    log.warn('test')
    assert log_stream.getvalue() == 'WARNING:root:test\n'

Then run python3 -m pytest -v. Note that running each test individually works. The settings should not interfere, since they are in separate files.

@nicoddemus
Copy link
Member

As discussed in #2159, the recommendation (at least for now) is to use the pytest-catchlog plugin.

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

2 participants