Overview
pytest 7.0, released on February 1, 2023, adds the pythonpath setting and improves test node ID handling.
Main Features
pythonpath setting
The new pythonpath setting in pyproject.toml adds directories to sys.path without manually manipulating the environment.
python
# pyproject.toml
# [tool.pytest.ini_options]
# pythonpath = ["src", "lib"]
# With this configuration, imports work
# directly from src/ and lib/
# without installing the package or modifying PYTHONPATH
# test_app.py
from my_app.services import compute_total
def test_computation():
assert compute_total([10, 20, 30]) == 60
Improved node IDs
Node IDs are now more readable and consistent, making it easier to filter tests and understand execution reports.
python
import pytest
@pytest.mark.parametrize('input_,expected', [
([1, 2, 3], 6),
([], 0),
([10], 10),
])
def test_sum(input_, expected):
assert sum(input_) == expected
# Improved node IDs:
# test_math.py::test_sum[input_0-6]
# test_math.py::test_sum[input_1-0]
# pytest -k 'test_sum[input_0]' to filter
