Skip to content

Commit 6972464

Browse files
henryiiilaydaypre-commit-ci[bot]
authored
tests: better support for parallel testing (#871)
* tests: better support for parallel testing Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * tests: only copy setuptools Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Update tests/conftest.py Co-authored-by: layday <layday@protonmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: layday <layday@protonmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e04c72a commit 6972464

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tests/conftest.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
import tempfile
1313

1414
from functools import partial, update_wrapper
15+
from pathlib import Path
1516

1617
import pytest
1718

1819
import build.env
1920

21+
from build._compat import tomllib
22+
2023

2124
def pytest_addoption(parser):
2225
os.environ['PYTHONWARNINGS'] = 'ignore:DEPRECATION::pip._internal.cli.base_command' # for when not run within tox
@@ -101,10 +104,28 @@ def packages_path():
101104
return os.path.realpath(os.path.join(__file__, '..', 'packages'))
102105

103106

107+
def is_setuptools(package_path):
108+
if package_path.joinpath('setup.py').is_file():
109+
return True
110+
pyproject = package_path / 'pyproject.toml'
111+
try:
112+
with pyproject.open('rb') as f:
113+
pp = tomllib.load(f)
114+
except (FileNotFoundError, ValueError):
115+
return True
116+
return 'setuptools' in pp.get('build-system', {}).get('build-backend', 'setuptools')
117+
118+
104119
def generate_package_path_fixture(package_name):
105120
@pytest.fixture
106-
def fixture(packages_path):
107-
return os.path.join(packages_path, package_name)
121+
def fixture(packages_path, tmp_path):
122+
package_path = Path(packages_path) / package_name
123+
if not is_setuptools(package_path):
124+
return str(package_path)
125+
126+
new_path = tmp_path / package_name
127+
shutil.copytree(package_path, new_path)
128+
return str(new_path)
108129

109130
return fixture
110131

0 commit comments

Comments
 (0)