Skip to content

Commit e674677

Browse files
committed
Add pytest fixtures to get the path to a test sdist and test wheel
To avoid creating these over and over again, create the sdist and wheel in a temporary direcory with lifetime related to the test session scope.
1 parent 0f06e29 commit e674677

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

tests/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import getpass
22
import logging.config
3+
import pathlib
4+
import tempfile
35
import textwrap
46

57
import pytest
@@ -8,6 +10,9 @@
810
from twine import settings
911
from twine import utils
1012

13+
from .helpers import build_sdist
14+
from .helpers import build_wheel
15+
1116

1217
@pytest.fixture(autouse=True)
1318
def configure_output():
@@ -83,3 +88,31 @@ def _settings(config=default_config, **settings_kwargs):
8388
@pytest.fixture
8489
def entered_password(monkeypatch):
8590
monkeypatch.setattr(getpass, "getpass", lambda prompt: "entered pw")
91+
92+
93+
@pytest.fixture(scope="session")
94+
def tmp_path_session(tmp_path_factory):
95+
return pathlib.Path(
96+
tempfile.mkdtemp(
97+
prefix="twine-test-",
98+
dir=tmp_path_factory.mktemp("test"),
99+
)
100+
)
101+
102+
103+
@pytest.fixture
104+
def test_wheel(tmp_path_session):
105+
return build_wheel(tmp_path_session, "test", "1.2.3", {})
106+
107+
108+
@pytest.fixture
109+
def test_wheel_signature(test_wheel):
110+
signature = test_wheel.with_suffix(".whl.asc")
111+
signature.write_text("-----BEGIN PGP SIGNATURE-----")
112+
yield signature
113+
signature.unlink()
114+
115+
116+
@pytest.fixture
117+
def test_sdist(tmp_path_session):
118+
return build_sdist(tmp_path_session, "test", "1.2.3", {})

tests/test_package.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def test_package_signed_name_is_correct():
116116
assert package.signed_filename == (filename + ".asc")
117117

118118

119-
def test_package_add_attestations(tmp_path):
120-
package = package_file.PackageFile.from_filename(helpers.WHEEL_FIXTURE, None)
119+
def test_package_add_attestations(tmp_path, test_wheel):
120+
package = package_file.PackageFile.from_filename(test_wheel, None)
121121

122122
assert package.attestations is None
123123

0 commit comments

Comments
 (0)