Skip to content
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

Logging gobbled up after pytest.main executed #3450

Open
westhomas opened this issue May 4, 2018 · 1 comment
Open

Logging gobbled up after pytest.main executed #3450

westhomas opened this issue May 4, 2018 · 1 comment
Labels
plugin: logging related to the logging builtin plugin

Comments

@westhomas
Copy link
Contributor

westhomas commented May 4, 2018

I'm having some issues with my logs being gobbled up after I execute pytest.main. But it seems to be related to using logging.config.dictConfig. When I manually configure my logging, it seems to work.

Overall, I'm just confused as to what's going on. Here's a sample. logging_option1 works while logging_option2 does not.

# test_pytestmain.py
import logging

logger = logging.getLogger(__name__)

def logging_option1():
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

def logging_option2():
    import logging.config
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'handlers': {
            'console': {
                'class': 'logging.StreamHandler',
            }
        },
        'loggers': {
            '': {
                'handlers': ['console'],
                'level': 'DEBUG',
            }
        }
    }
    logging.config.dictConfig(LOGGING)


def test_dummy():
    logger.info("LOG: inside test")
    assert True



# THIS WORKS
logging_option1()

# THIS DOESN'T
# logging_option2()


if __name__ == '__main__':

    logger.info("LOG: test starting")

    import pytest
    returncode = pytest.main([
        "test_pytestmain.py"
    ])

    logger.info("LOG: test ended with return code: %s", returncode)
@pytestbot pytestbot added the plugin: logging related to the logging builtin plugin label May 4, 2018
@nicoddemus
Copy link
Member

nicoddemus commented May 4, 2018

Hmm unfortunately logging configuration is always global so it might be tricky to "undo" the changes in configuration that pytest does to capture logging. A few things to try:

  1. Disable the logging plugin in case you are not really interested on it: returncode = pytest.main(["test_pytestmain.py", '-p', 'no:logging'])
  2. Test the features branch, this might be related with logging.py: Don't change log level of the root logger to bigger numeric value #3307. To install the features branch:
    pip install git+https://github.com/pytest-dev/pytest.git@features
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: logging related to the logging builtin plugin
Projects
None yet
Development

No branches or pull requests

3 participants