Skip to content

Commit 49d2919

Browse files
authored
Improve nox test execution setup (#7153)
2 parents 6d86a04 + db5432b commit 49d2919

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

noxfile.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ def get_author_list():
4747
return sorted(authors, key=lambda x: x.lower())
4848

4949

50-
def protected_pip(*arguments):
51-
"""Get arguments for session.run, that use a "protected" pip.
50+
def run_with_protected_pip(session, *arguments):
51+
"""Do a session.run("pip", *arguments), using a "protected" pip.
5252
5353
This invokes a wrapper script, that forwards calls to original virtualenv
5454
(stable) version, and not the code being tested. This ensures pip being
5555
used is not the code being tested.
5656
"""
57-
return ("python", LOCATIONS["protected-pip"]) + arguments
57+
env = {"VIRTUAL_ENV": session.virtualenv.location}
58+
59+
command = ("python", LOCATIONS["protected-pip"]) + arguments
60+
kwargs = {"env": env, "silent": True}
61+
session.run(*command, **kwargs)
5862

5963

6064
def should_update_common_wheels():
@@ -84,15 +88,35 @@ def should_update_common_wheels():
8488
def test(session):
8589
# Get the common wheels.
8690
if should_update_common_wheels():
87-
session.run(*protected_pip(
91+
run_with_protected_pip(
92+
session,
8893
"wheel",
8994
"-w", LOCATIONS["common-wheels"],
9095
"-r", REQUIREMENTS["common-wheels"],
91-
))
96+
)
97+
else:
98+
msg = (
99+
"Re-using existing common-wheels at {}."
100+
.format(LOCATIONS["common-wheels"])
101+
)
102+
session.log(msg)
103+
104+
# Build source distribution
105+
sdist_dir = os.path.join(session.virtualenv.location, "sdist")
106+
session.run(
107+
"python", "setup.py", "sdist",
108+
"--formats=zip", "--dist-dir", sdist_dir,
109+
silent=True,
110+
)
111+
generated_files = os.listdir(sdist_dir)
112+
assert len(generated_files) == 1
113+
generated_sdist = os.path.join(sdist_dir, generated_files[0])
114+
115+
# Install source distribution
116+
run_with_protected_pip(session, "install", generated_sdist)
92117

93-
# Install sources and dependencies
94-
session.run(*protected_pip("install", "."))
95-
session.run(*protected_pip("install", "-r", REQUIREMENTS["tests"]))
118+
# Install test dependencies
119+
run_with_protected_pip(session, "install", "-r", REQUIREMENTS["tests"])
96120

97121
# Parallelize tests as much as possible, by default.
98122
arguments = session.posargs or ["-n", "auto"]

0 commit comments

Comments
 (0)