I have a test that I am running with:
pytest --capture=no --verbose --rootdir=testing/ testing/tests/docker_test.py
from /home/user/development/
. The test checks if some containers are running and uses the default logging framework of Python 3.6. The logger inside the test file is configured as follows:
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logging.basicConfig(level=logging.INFO, stream=sys.stdout, format="%(asctime)s %(levelname)s %(message)s")
Inside tests I am using the logger as follows:
logger.info(f"TEST SUCCESSFUL: container {container_name} is running")
logger.info(f"TEST SUCCESSFUL: all required containers are running")
Inside testing
(the root directory) I have a file pytest.ini
:
[pytest]
log_level = INFO
log_cli_level = INFO
log_format = %(asctime)s %(levelname)s %(message)s
log_cli_format = %(asctime)s %(levelname)s %(message)s
log_date_format = %H:%M:%S
log_cli_date_format = %H:%M:%S
Basically I do not want any date to be in the timestamp and I want pytest to log live to the command line when I am running the tests.
For one I am wondering what asctime
stands for. It looks like "ascii time". I do not want a standardized timestamp, but instead the format I describe in the pytest.ini
. That is why I also tried to use date
, datetime
and timestamp
, instead of asctime
, all resulting in an error. So I guess asctime
is the only way to get a timestamp.
However, pytest seems to ignore all the options I am setting in my pytest.ini
file, although is indicates, that it found the file, when I am running the tests:
cachedir: testing/.pytest_cache
rootdir: /home/user/development/testing, inifile: pytest.ini
How can I change the timestamp in pytest logging?