Skip to content

Conversation

@embray
Copy link
Member

@embray embray commented Aug 31, 2013

In the process of testing the 0.2.4 release I experienced two test failures on my own system when running astropy.test() in a Python session. Both failures were in the logging module and looked something like this:

_______________________________________________ test_log_to_file[level0] _______________________________________________

tmpdir = local('/tmp/pytest-70/test_log_to_file_level0_0'), level = None

    @pytest.mark.parametrize(('level'), [None, 'DEBUG', 'INFO', 'WARN', 'ERROR'])
    def test_log_to_file(tmpdir, level):

        local_path = tmpdir.join('test.log')
        log_file = local_path.open('wb')
        log_path = str(local_path.realpath())

        if level is not None:
            log.setLevel(level)

        with log.log_to_file(log_path):
            log.error("Error message")
            log.warning("Warning message")
            log.info("Information message")
            log.debug("Debug message")

        log_file.close()

        log_file = local_path.open('rb')
        log_entries = log_file.readlines()
        log_file.close()

        # Check list length
        if level == 'DEBUG':
            assert len(log_entries) == 4
        elif level is None or level == 'INFO':
>           assert len(log_entries) == 3
E           assert 4 == 3
E            +  where 4 = len(["'2013-07-24 14:40:15,046', 'astropy.tests.test_logger', 'ERROR', 'Error message'\n", "'2013-07-24 14:40:15,046', 'as...'INFO', 'Information message'\n", "'2013-07-24 14:40:15,047', 'astropy.tests.test_logger', 'DEBUG', 'Debug message'\n"])

../../home/embray/.virtualenvs/astropy-release-test/lib/python2.7/site-packages/astropy/tests/test_logger.py:323: AssertionError
--------------------------------------------------- Captured stdout ----------------------------------------------------
ERROR: Error message [astropy.tests.test_logger]
WARNING: Warning message [astropy.tests.test_logger]
INFO: Information message [astropy.tests.test_logger]
DEBUG: Debug message [astropy.tests.test_logger]

I realized that this was just occurring because in my ~/.astropy/config/astropy.cfg I set the log level to DEBUG, whereas the default should be INFO. I thought we had fixed the tests to always use the default config settings... Or am I mistaken on that? (Note: I do see potential value in being able to run the tests with different local config values, but if that's a desirable thing to do the tests need to be designed to support different configurations where applicable).

…didn't solve the issue but it seems worthwhile
@embray
Copy link
Member Author

embray commented Aug 31, 2013

After looking into this a bit more now, it's clear to me that this behavior only applies when running astropy.test() and not when running, for example, ./setup.py test. The test command does set XDG_CONFIG_HOME and friends to a temp dir, thus avoiding this kind of configuration issue. But just running the test() function does not do this--and maybe that's desirable as it allows running the tests in one's own configuration. That said, these logging tests should still be more robust to differences in the user's config.

@embray
Copy link
Member Author

embray commented Aug 31, 2013

The attached changes fix the specific tests that were bombing out. It does not change how astropy.test() handles default config values, but I'm fine with keeping the current behavior, upon further thought. It makes sense to me that running astropy.test() should run it with whatever configuration the astropy module is using in that interpreter session...

embray added a commit that referenced this pull request Sep 4, 2013
Logging tests not using default config values?
@embray embray merged commit 5b99005 into astropy:master Sep 4, 2013
@embray embray deleted the issue-1284 branch September 4, 2013 15:32
embray added a commit that referenced this pull request Sep 6, 2013
Logging tests not using default config values?
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

Successfully merging this pull request may close these issues.

1 participant