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

View File

@ -1,11 +1,15 @@
from pathlib import Path
import importlib.metadata
import packaging.version
import pytest
import setuptools
import yaml
from pyproject_buildrequires import generate_requires
SETUPTOOLS_VERSION = packaging.version.parse(setuptools.__version__)
SETUPTOOLS_60 = SETUPTOOLS_VERSION >= packaging.version.parse('60')
testcases = {}
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'):
pytest.xfail(case.get('xfail'))
if case.get('skipif') and eval(case.get('skipif')):
pytest.skip(case.get('skipif'))
for filename in case:
file_types = ('.toml', '.py', '.in', '.ini', '.txt')
file_types = ('.toml', '.py', '.in', '.ini', '.txt', '.cfg')
if filename.endswith(file_types):
cwd.joinpath(filename).write_text(case[filename])