pytest-dev / pytest-dev/pytest-xdist

xdist + logging + @parametrize log on file only the latest test execution

Open
#567 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.9k
Forks
287
Avg merge
9h 30m
Merged PRs (30d)
2

Description

pytest.ini

[pytest]
python_files = test_*
python_classes = Test*
python_functions = test_*
log_cli = True
log_cli_level = DEBUG
log_cli_format = %(asctime)s %(filename)s %(funcName)s %(levelname)s %(message)s
log_cli_date_format = %d-%m-%Y %H:%M:%S
log_file = log.log
log_file_level = DEBUG
log_file_format = %(asctime)s %(filename)s %(funcName)s %(levelname)s %(message)s
log_file_date_format = %d-%m-%Y %H:%M:%S

if test file is

import requests
import pytest
from pytest import mark
import logging
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("urllib3").propagate = False

@mark.parametrize('endpoint', [
    "https://a.com",
    "https://b.com",
    "https://c.com",
    "https://d.com"
])
def test_endpoints(endpoint):
    logging.debug(endpoint)

you don't obtain any console output due to https://github.com/pytest-dev/pytest-xdist/issues/402 ,

but there is something strange also with the file log.

running the test without the use of xdist:

image

the log file is

03-08-2020 15:41:52 test_dist_parametrized.py test_endpoints DEBUG https://a.com
03-08-2020 15:41:52 test_dist_parametrized.py test_endpoints DEBUG https://b.com
03-08-2020 15:41:52 test_dist_parametrized.py test_endpoints DEBUG https://c.com
03-08-2020 15:41:52 test_dist_parametrized.py test_endpoints DEBUG https://d.com

using xdist the log file contains

03-08-2020 15:43:56 test_dist_parametrized.py test_endpoints DEBUG https://c.com

it contains only the log of the latest test executed ( c.com )

image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the pytest.ini logging configuration and reproduce the behavior using test_dist_parametrized.py with the four parametrized endpoints, both with and without xdist. Trace how workers open or write log.log, then verify that the xdist run preserves log records from every test execution rather than only the latest one.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.