Check that with live logging enable we are printing the correct headers during start/setup/call/teardown/finish.
(
pytester: Pytester, request: FixtureRequest
)
| 277 | |
| 278 | |
| 279 | def test_log_cli_default_level_sections( |
| 280 | pytester: Pytester, request: FixtureRequest |
| 281 | ) -> None: |
| 282 | """Check that with live logging enable we are printing the correct headers during |
| 283 | start/setup/call/teardown/finish.""" |
| 284 | filename = request.node.name + ".py" |
| 285 | pytester.makeconftest( |
| 286 | """ |
| 287 | import pytest |
| 288 | import logging |
| 289 | |
| 290 | def pytest_runtest_logstart(): |
| 291 | logging.warning('>>>>> START >>>>>') |
| 292 | |
| 293 | def pytest_runtest_logfinish(): |
| 294 | logging.warning('<<<<< END <<<<<<<') |
| 295 | """ |
| 296 | ) |
| 297 | |
| 298 | pytester.makepyfile( |
| 299 | """ |
| 300 | import pytest |
| 301 | import logging |
| 302 | |
| 303 | @pytest.fixture |
| 304 | def fix(request): |
| 305 | logging.warning("log message from setup of {}".format(request.node.name)) |
| 306 | yield |
| 307 | logging.warning("log message from teardown of {}".format(request.node.name)) |
| 308 | |
| 309 | def test_log_1(fix): |
| 310 | logging.warning("log message from test_log_1") |
| 311 | |
| 312 | def test_log_2(fix): |
| 313 | logging.warning("log message from test_log_2") |
| 314 | """ |
| 315 | ) |
| 316 | pytester.makeini( |
| 317 | """ |
| 318 | [pytest] |
| 319 | log_cli=true |
| 320 | """ |
| 321 | ) |
| 322 | |
| 323 | result = pytester.runpytest() |
| 324 | result.stdout.fnmatch_lines( |
| 325 | [ |
| 326 | f"{filename}::test_log_1 ", |
| 327 | "*-- live log start --*", |
| 328 | "*WARNING* >>>>> START >>>>>*", |
| 329 | "*-- live log setup --*", |
| 330 | "*WARNING*log message from setup of test_log_1*", |
| 331 | "*-- live log call --*", |
| 332 | "*WARNING*log message from test_log_1*", |
| 333 | "PASSED *50%*", |
| 334 | "*-- live log teardown --*", |
| 335 | "*WARNING*log message from teardown of test_log_1*", |
| 336 | "*-- live log finish --*", |
nothing calls this directly
no test coverage detected