Tests: Make them pass with setuptools < 60

This makes the tests work on EL 9 and Fedora 36.

 - Move metadata to setup.cfg in self-referential extras tests
 - Skip tests for pyproject.toml [project] metadata when setuptools < 60

Related: rhbz#2208971
This commit is contained in:
Miro Hrončok 2023-04-27 18:11:40 +02:00
parent 500d43c1c0
commit 3fae95fe3a
2 changed files with 48 additions and 36 deletions

View File

@ -837,6 +837,7 @@ Stdout from wrapped subprocess does not appear in output:
result: 0 result: 0
pyproject.toml with runtime dependencies: pyproject.toml with runtime dependencies:
skipif: not SETUPTOOLS_60
installed: installed:
setuptools: 50 setuptools: 50
wheel: 1 wheel: 1
@ -859,6 +860,7 @@ pyproject.toml with runtime dependencies:
result: 0 result: 0
pyproject.toml with runtime dependencies and partially selected extras: pyproject.toml with runtime dependencies and partially selected extras:
skipif: not SETUPTOOLS_60
installed: installed:
setuptools: 50 setuptools: 50
wheel: 1 wheel: 1
@ -887,7 +889,7 @@ pyproject.toml with runtime dependencies and partially selected extras:
python3dist(pytest-mock) python3dist(pytest-mock)
result: 0 result: 0
pyproject.toml with runtime dependencies and self-referencing extras (sooner): Self-referencing extras (sooner):
installed: installed:
setuptools: 50 setuptools: 50
wheel: 1 wheel: 1
@ -898,17 +900,18 @@ pyproject.toml with runtime dependencies and self-referencing extras (sooner):
[build-system] [build-system]
requires = ["setuptools"] requires = ["setuptools"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[project] setup.cfg: |
name = "my_package" [metadata]
version = "0.1" name = my_package
dependencies = [ version = 0.1
"foo", [options]
'importlib-metadata; python_version<"3.8"', install_requires =
] foo
[project.optional-dependencies] importlib-metadata; python_version<"3.8"
tests = ["pytest>=5", "pytest-mock"] [options.extras_require]
docs = ["sphinx", "python-docs-theme"] tests = pytest>=5; pytest-mock
dev = ["my_package[docs,tests]"] docs = sphinx; python-docs-theme
dev = my_package[docs,tests]
expected: | expected: |
python3dist(setuptools) python3dist(setuptools)
python3dist(wheel) python3dist(wheel)
@ -919,7 +922,7 @@ pyproject.toml with runtime dependencies and self-referencing extras (sooner):
python3dist(pytest-mock) python3dist(pytest-mock)
result: 0 result: 0
pyproject.toml with runtime dependencies and self-referencing extras (later): Self-referencing extras (later):
installed: installed:
setuptools: 50 setuptools: 50
wheel: 1 wheel: 1
@ -930,17 +933,18 @@ pyproject.toml with runtime dependencies and self-referencing extras (later):
[build-system] [build-system]
requires = ["setuptools"] requires = ["setuptools"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[project] setup.cfg: |
name = "my_package" [metadata]
version = "0.1" name = my_package
dependencies = [ version = 0.1
"foo", [options]
'importlib-metadata; python_version<"3.8"', install_requires =
] foo
[project.optional-dependencies] importlib-metadata; python_version<"3.8"
tests = ["pytest>=5", "pytest-mock"] [options.extras_require]
docs = ["sphinx", "python-docs-theme"] tests = pytest>=5; pytest-mock
xdev = ["my_package[docs,tests]"] docs = sphinx; python-docs-theme
xdev = my_package[docs,tests]
expected: | expected: |
python3dist(setuptools) python3dist(setuptools)
python3dist(wheel) python3dist(wheel)
@ -951,7 +955,7 @@ pyproject.toml with runtime dependencies and self-referencing extras (later):
python3dist(pytest-mock) python3dist(pytest-mock)
result: 0 result: 0
pyproject.toml with runtime dependencies and self-referencing extras (maze): Self-referencing extras (maze):
installed: installed:
setuptools: 50 setuptools: 50
wheel: 1 wheel: 1
@ -962,16 +966,17 @@ pyproject.toml with runtime dependencies and self-referencing extras (maze):
[build-system] [build-system]
requires = ["setuptools"] requires = ["setuptools"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[project] setup.cfg: |
name = "my_package" [metadata]
version = "0.1" name = my_package
[project.optional-dependencies] version = 0.1
start = ["my_package[left,right]", "startdep"] [options.extras_require]
left = ["my_package[right,forward]", "leftdep"] start = my_package[left,right]; startdep
right = ["my_package[left,forward]", "rightdep"] left = my_package[right,forward]; leftdep
forward = ["my_package[backward]", "forwarddep"] right = my_package[left,forward]; rightdep
backward = ["my_package[left,right]", "backwarddep"] forward = my_package[backward]; forwarddep
never = ["my_package[forward]", "neverdep"] backward = my_package[left,right]; backwarddep
never = my_package[forward]; neverdep
expected: | expected: |
python3dist(setuptools) python3dist(setuptools)
python3dist(wheel) python3dist(wheel)

View File

@ -1,11 +1,15 @@
from pathlib import Path from pathlib import Path
import importlib.metadata import importlib.metadata
import packaging.version
import pytest import pytest
import setuptools
import yaml import yaml
from pyproject_buildrequires import generate_requires from pyproject_buildrequires import generate_requires
SETUPTOOLS_VERSION = packaging.version.parse(setuptools.__version__)
SETUPTOOLS_60 = SETUPTOOLS_VERSION >= packaging.version.parse('60')
testcases = {} testcases = {}
with Path(__file__).parent.joinpath('pyproject_buildrequires_testcases.yaml').open() as f: with Path(__file__).parent.joinpath('pyproject_buildrequires_testcases.yaml').open() as f:
@ -26,8 +30,11 @@ def test_data(case_name, capfd, tmp_path, monkeypatch):
if case.get('xfail'): if case.get('xfail'):
pytest.xfail(case.get('xfail')) pytest.xfail(case.get('xfail'))
if case.get('skipif') and eval(case.get('skipif')):
pytest.skip(case.get('skipif'))
for filename in case: for filename in case:
file_types = ('.toml', '.py', '.in', '.ini', '.txt') file_types = ('.toml', '.py', '.in', '.ini', '.txt', '.cfg')
if filename.endswith(file_types): if filename.endswith(file_types):
cwd.joinpath(filename).write_text(case[filename]) cwd.joinpath(filename).write_text(case[filename])