Small improvements to tests suggested during review
This commit is contained in:
parent
c53b72fd7b
commit
5d89a93977
|
@ -189,6 +189,7 @@ class LogCaptureFixture(object):
|
||||||
"""
|
"""
|
||||||
logger_name = logger
|
logger_name = logger
|
||||||
logger = logging.getLogger(logger_name)
|
logger = logging.getLogger(logger_name)
|
||||||
|
# save the original log-level to restore it during teardown
|
||||||
self._initial_log_levels.setdefault(logger_name, logger.level)
|
self._initial_log_levels.setdefault(logger_name, logger.level)
|
||||||
logger.setLevel(level)
|
logger.setLevel(level)
|
||||||
|
|
||||||
|
|
|
@ -171,22 +171,17 @@ def test_log_cli_default_level(testdir):
|
||||||
assert plugin.log_cli_handler.level == logging.NOTSET
|
assert plugin.log_cli_handler.level == logging.NOTSET
|
||||||
logging.getLogger('catchlog').info("INFO message won't be shown")
|
logging.getLogger('catchlog').info("INFO message won't be shown")
|
||||||
logging.getLogger('catchlog').warning("WARNING message will be shown")
|
logging.getLogger('catchlog').warning("WARNING message will be shown")
|
||||||
print('PASSED')
|
|
||||||
''')
|
''')
|
||||||
testdir.makeini('''
|
testdir.makeini('''
|
||||||
[pytest]
|
[pytest]
|
||||||
log_cli=true
|
log_cli=true
|
||||||
''')
|
''')
|
||||||
|
|
||||||
result = testdir.runpytest('-s')
|
result = testdir.runpytest()
|
||||||
|
|
||||||
# fnmatch_lines does an assertion internally
|
# fnmatch_lines does an assertion internally
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
'test_log_cli_default_level.py*',
|
'test_log_cli_default_level.py*WARNING message will be shown*',
|
||||||
'PASSED', # 'PASSED' on its own line because the log message prints a new line
|
|
||||||
])
|
|
||||||
result.stdout.fnmatch_lines([
|
|
||||||
'*WARNING message will be shown*',
|
|
||||||
])
|
])
|
||||||
assert "INFO message won't be shown" not in result.stdout.str()
|
assert "INFO message won't be shown" not in result.stdout.str()
|
||||||
# make sure that that we get a '0' exit code for the testsuite
|
# make sure that that we get a '0' exit code for the testsuite
|
||||||
|
@ -214,12 +209,9 @@ def test_log_cli_level(testdir):
|
||||||
|
|
||||||
# fnmatch_lines does an assertion internally
|
# fnmatch_lines does an assertion internally
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
'test_log_cli_level.py*',
|
'test_log_cli_level.py*This log message will be shown',
|
||||||
'PASSED', # 'PASSED' on its own line because the log message prints a new line
|
'PASSED', # 'PASSED' on its own line because the log message prints a new line
|
||||||
])
|
])
|
||||||
result.stdout.fnmatch_lines([
|
|
||||||
"* This log message will be shown"
|
|
||||||
])
|
|
||||||
for line in result.outlines:
|
for line in result.outlines:
|
||||||
try:
|
try:
|
||||||
assert "This log message won't be shown" in line
|
assert "This log message won't be shown" in line
|
||||||
|
@ -234,12 +226,9 @@ def test_log_cli_level(testdir):
|
||||||
|
|
||||||
# fnmatch_lines does an assertion internally
|
# fnmatch_lines does an assertion internally
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
'test_log_cli_level.py*',
|
'test_log_cli_level.py* This log message will be shown',
|
||||||
'PASSED', # 'PASSED' on its own line because the log message prints a new line
|
'PASSED', # 'PASSED' on its own line because the log message prints a new line
|
||||||
])
|
])
|
||||||
result.stdout.fnmatch_lines([
|
|
||||||
"* This log message will be shown"
|
|
||||||
])
|
|
||||||
for line in result.outlines:
|
for line in result.outlines:
|
||||||
try:
|
try:
|
||||||
assert "This log message won't be shown" in line
|
assert "This log message won't be shown" in line
|
||||||
|
@ -273,12 +262,9 @@ def test_log_cli_ini_level(testdir):
|
||||||
|
|
||||||
# fnmatch_lines does an assertion internally
|
# fnmatch_lines does an assertion internally
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
'test_log_cli_ini_level.py*',
|
'test_log_cli_ini_level.py* This log message will be shown',
|
||||||
'PASSED', # 'PASSED' on its own line because the log message prints a new line
|
'PASSED', # 'PASSED' on its own line because the log message prints a new line
|
||||||
])
|
])
|
||||||
result.stdout.fnmatch_lines([
|
|
||||||
"* This log message will be shown"
|
|
||||||
])
|
|
||||||
for line in result.outlines:
|
for line in result.outlines:
|
||||||
try:
|
try:
|
||||||
assert "This log message won't be shown" in line
|
assert "This log message won't be shown" in line
|
||||||
|
|
Loading…
Reference in New Issue