Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tests: better support for parallel testing #871

Merged
merged 4 commits into from
Mar 9, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
import tempfile

from functools import partial, update_wrapper
from pathlib import Path

import pytest

import build.env

if sys.version_info < (3, 11):
import tomli as tomllib
else:
import tomllib


def pytest_addoption(parser):
os.environ['PYTHONWARNINGS'] = 'ignore:DEPRECATION::pip._internal.cli.base_command' # for when not run within tox
Expand Down Expand Up @@ -101,10 +107,29 @@ def packages_path():
return os.path.realpath(os.path.join(__file__, '..', 'packages'))


def is_setuptools(package_path):
if package_path.joinpath("setup.py").is_file():
return True
pyproject = package_path / "pyproject.toml"
try:
with pyproject.open("rb") as f:
pp = tomllib.load(f)
except (FileNotFoundError, ValueError):
return True
return "setuptools" in pp.get("build-system", {}).get("build-backend", "setuptools")



def generate_package_path_fixture(package_name):
@pytest.fixture
def fixture(packages_path):
return os.path.join(packages_path, package_name)
def fixture(packages_path, tmp_path):
package_path = Path(packages_path) / package_name
if not is_setuptools(package_path):
return str(package_path)

new_path = tmp_path / package_name
shutil.copytree(package_path, new_path)
return str(new_path)

return fixture

Expand Down
Loading