Skip to content

Commit c340d7e

Browse files
committed
test: Skip build/install steps with nox's --no-install flag
This saves time when you want to rerun the test suite with different pytest arguments but you haven't made any code changes in-between.
1 parent 7c218b9 commit c340d7e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
args: ["--pretty", "--show-error-codes"]
3636
additional_dependencies: [
3737
'keyring==24.2.0',
38-
'nox==2023.4.22',
38+
'nox==2024.03.02',
3939
'pytest',
4040
'types-docutils==0.20.0.3',
4141
'types-setuptools==68.2.0.0',

noxfile.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
nox.options.reuse_existing_virtualenvs = True
2121
nox.options.sessions = ["lint"]
22+
nox.needs_version = ">=2024.03.02" # for session.run_install()
2223

2324
LOCATIONS = {
2425
"common-wheels": "tests/data/common_wheels",
@@ -44,7 +45,9 @@ def run_with_protected_pip(session: nox.Session, *arguments: str) -> None:
4445
env = {"VIRTUAL_ENV": session.virtualenv.location}
4546

4647
command = ("python", LOCATIONS["protected-pip"]) + arguments
47-
session.run(*command, env=env, silent=True)
48+
# By using run_install(), these installation steps can be skipped when -R
49+
# or --no-install is passed.
50+
session.run_install(*command, env=env, silent=True)
4851

4952

5053
def should_update_common_wheels() -> bool:
@@ -84,8 +87,13 @@ def test(session: nox.Session) -> None:
8487
session.log(msg)
8588

8689
# Build source distribution
90+
# HACK: we want to skip building and installing pip when nox's --no-install
91+
# flag is given (to save time when running tests back to back with different
92+
# arguments), but unfortunately nox does not expose this configuration state
93+
# yet. https://github.com/wntrblm/nox/issues/710
94+
no_install = "-R" in sys.argv or "--no-install" in sys.argv
8795
sdist_dir = os.path.join(session.virtualenv.location, "sdist")
88-
if os.path.exists(sdist_dir):
96+
if not no_install and os.path.exists(sdist_dir):
8997
shutil.rmtree(sdist_dir, ignore_errors=True)
9098

9199
run_with_protected_pip(session, "install", "build")
@@ -94,7 +102,7 @@ def test(session: nox.Session) -> None:
94102
# pip, so uninstall pip to force build to provision a known good version of pip.
95103
run_with_protected_pip(session, "uninstall", "pip", "-y")
96104
# fmt: off
97-
session.run(
105+
session.run_install(
98106
"python", "-I", "-m", "build", "--sdist", "--outdir", sdist_dir,
99107
silent=True,
100108
)

0 commit comments

Comments
 (0)