pytest-dev / pytest-dev/pytest-xdist
Individual log files not created for each worker
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 287
- Avg merge
- 9h 30m
- Merged PRs (30d)
- 2
Description
I am trying to get log file for each worker. I have followed https://github.com/pytest-dev/pytest-xdist/issues/331. I have added code in conftest.py and pytest.ini file, but still separate log files are not generated. Below are the details of my files. @nbartos @nicoddemus @marcosanchotene Could someone please help me out.
Also how the value of PYTEST_XDIST_WORKER' is picked up do we need to define it somewhere. I am invoking my tests from commandline through this pytest -v -s -m "smoke or regression" -n 3 --worker-log-file Logs/pytest-%w.log TestCases/
My pytest.ini file
[pytest]
worker_log_file = Logs/pytest-%w.log
log_file_format = [%(asctime)s %(levelname)s %(filename)s %(lineno)s] %(message)s
log_file_level = INFO
My conftest.py file code
import os
from selenium import webdriver
import logging
import pytest
from Utilities.readProperties import ReadConfig
from dotenv import load_dotenv
# Load environment variables from the .env file
load_dotenv()
def pytest_addoption(parser): # This will get the value from Commandline
parser.addoption("--browser")
parser.addoption("--mode")
log_help_text = 'Similar to log_file, but %%w will be replaced with a worker identifier.'
parser.addini('worker_log_file', help=log_help_text)
log_group = parser.getgroup('logging')
log_group.addoption('--worker-log-file', dest='worker_log_file', help=log_help_text)
def pytest_configure(config):
configure_logger(config)
def configure_logger(config):
if is_xdist_enabled():
log_file = config.getini('worker_log_file')
logging.basicConfig(
format=config.getini('log_file_format'),
filename=log_file.replace('%w', os.environ.get('PYTEST_XDIST_WORKER')),
level=config.getini('log_file_level')
)
def is_xdist_enabled():
return os.environ.get('PYTEST_XDIST_WORKER') is not None
Contributor guide
No contributing guide indexed for this repository
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
Start with the conftest.py and pytest.ini examples, then compare the command-line option with the registered configuration setting. Check how PYTEST_XDIST_WORKER is provided during distributed runs and whether the worker log path is resolved as expected. Done means the supplied invocation creates a distinct log file for each worker.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- distributed-systems, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100