|
1 | 1 | # -*- coding: utf-8 -*- |
| 2 | +import re |
2 | 3 | import os |
3 | 4 |
|
4 | 5 | import six |
@@ -293,6 +294,64 @@ def test_log_2(fix): |
293 | 294 | ]) |
294 | 295 |
|
295 | 296 |
|
| 297 | +def test_sections_single_new_line_after_test_outcome(testdir, request): |
| 298 | + """Check that only a single new line is written between log messages during |
| 299 | + teardown/finish.""" |
| 300 | + filename = request.node.name + '.py' |
| 301 | + testdir.makeconftest(''' |
| 302 | + import pytest |
| 303 | + import logging |
| 304 | +
|
| 305 | + def pytest_runtest_logstart(): |
| 306 | + logging.warning('>>>>> START >>>>>') |
| 307 | +
|
| 308 | + def pytest_runtest_logfinish(): |
| 309 | + logging.warning('<<<<< END <<<<<<<') |
| 310 | + logging.warning('<<<<< END <<<<<<<') |
| 311 | + ''') |
| 312 | + |
| 313 | + testdir.makepyfile(''' |
| 314 | + import pytest |
| 315 | + import logging |
| 316 | +
|
| 317 | + @pytest.fixture |
| 318 | + def fix(request): |
| 319 | + logging.warning("log message from setup of {}".format(request.node.name)) |
| 320 | + yield |
| 321 | + logging.warning("log message from teardown of {}".format(request.node.name)) |
| 322 | + logging.warning("log message from teardown of {}".format(request.node.name)) |
| 323 | +
|
| 324 | + def test_log_1(fix): |
| 325 | + logging.warning("log message from test_log_1") |
| 326 | + ''') |
| 327 | + testdir.makeini(''' |
| 328 | + [pytest] |
| 329 | + log_cli=true |
| 330 | + ''') |
| 331 | + |
| 332 | + result = testdir.runpytest() |
| 333 | + result.stdout.fnmatch_lines([ |
| 334 | + '{}::test_log_1 '.format(filename), |
| 335 | + '*-- live log start --*', |
| 336 | + '*WARNING* >>>>> START >>>>>*', |
| 337 | + '*-- live log setup --*', |
| 338 | + '*WARNING*log message from setup of test_log_1*', |
| 339 | + '*-- live log call --*', |
| 340 | + '*WARNING*log message from test_log_1*', |
| 341 | + 'PASSED *100%*', |
| 342 | + '*-- live log teardown --*', |
| 343 | + '*WARNING*log message from teardown of test_log_1*', |
| 344 | + '*-- live log finish --*', |
| 345 | + '*WARNING* <<<<< END <<<<<<<*', |
| 346 | + '*WARNING* <<<<< END <<<<<<<*', |
| 347 | + '=* 1 passed in *=', |
| 348 | + ]) |
| 349 | + assert re.search(r'(.+)live log teardown(.+)\n(.+)WARNING(.+)\n(.+)WARNING(.+)', |
| 350 | + result.stdout.str(), re.MULTILINE) is not None |
| 351 | + assert re.search(r'(.+)live log finish(.+)\n(.+)WARNING(.+)\n(.+)WARNING(.+)', |
| 352 | + result.stdout.str(), re.MULTILINE) is not None |
| 353 | + |
| 354 | + |
296 | 355 | def test_log_cli_level(testdir): |
297 | 356 | # Default log file level |
298 | 357 | testdir.makepyfile(''' |
|
0 commit comments