pytest-dev / pytest-dev/pytest
Live logs questions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Our test automation is contains test which are more acceptance/end to end test like, than traditional unit tests. Also these test contains quite a lot of logging, so that they are easy to debug when errors do happen. If I want logging to logged without buffering to the console,, I need to enable live logging and from pytest.main(), I have these arguments defined: -o, log_cli=True, -o, log_cli_level=INFO, -o, log_cli_date_format=%Y-%m-%d %H:%M:%S, -o, log_cli_format=%(asctime)s,%(msecs)d [%(levelname)s] %(name)s: %(message)s. When I run this tests:
import logging
import time
log = logging.getLogger(__file__)
def test_01():
time.sleep(5)
log.info('This is from test01')
time.sleep(5)
log.info('This is from test01')
time.sleep(3)
assert True
Then I get this output:
------------------------------------------------------------- live log call --------------------------------------------------------------
2020-03-02 22:54:08,936 [INFO ] C:\repo\test_pytest.py: This is from test01
2020-03-02 22:54:13,464 [INFO ] C:\repo\test_pytest.py: This is from test01
PASSED [1/3]C:\repo\test_pytest.py: This is from test01
C:\repo\test_pytest.py: This is from test01
-
The logging from the test is show two times in the console. Once part of the live log and second time after a test is run. Is there way to prevent logging to happen two times and only preserve logs from live logs? When test is run in CI, I would like to follow in real time how test execution is proceeding, but I would like to prevent logging to happen two times.
-
If the above is someway possible is it someway possible to prevent those
-- live log call --lines to be present in the console logs?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the shown test and pytest.main() options for log_cli, log_cli_level, log_cli_date_format, and log_cli_format. Start by tracing pytest's live logging and post-test report output; done means each message appears once and the live log call header is omitted or configurable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, testing-qa
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100