Skip to content

Commit b976453

Browse files
committed
nox allows posargs in Session.notify()
1 parent e29745e commit b976453

File tree

4 files changed

+34
-37
lines changed

4 files changed

+34
-37
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Run Tests
2929
run: |
3030
npm install -g npm@v7.13.0
31-
nox -s test -- pytest[--headless]
31+
nox -s test -- --headless
3232
test-python-versions:
3333
runs-on: ${{ matrix.os }}
3434
strategy:
@@ -50,7 +50,7 @@ jobs:
5050
- name: Run Tests
5151
run: |
5252
npm install -g npm@v7.13.0
53-
nox -s test -- pytest[--headless,--no-cov]
53+
nox -s test -- --headless --no-cov
5454
test-javascript:
5555
runs-on: ubuntu-latest
5656
steps:

docs/source/developer-guide.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ If you prefer to run the tests using a headless browser:
164164

165165
.. code-block:: bash
166166
167-
nox -s test -- pytest[--headless]
167+
nox -s test -- --headless
168168
169169
You can pass other options to pytest in a similar manner:
170170

171171
.. code-block:: bash
172172
173-
nox -s test -- pytest[arg,--flag,--key=value]
173+
nox -s test -- arg --flag --key=value
174174
175175
176176
Running Javascript Tests

noxfile.py

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

3+
import functools
34
import os
45
import re
56
import subprocess
67
from pathlib import Path
7-
from typing import List, Tuple
8+
from typing import Any, Callable, Tuple
89

910
import nox
1011
from nox.sessions import Session
@@ -14,14 +15,27 @@
1415
POSARGS_PATTERN = re.compile(r"^(\w+)\[(.+)\]$")
1516

1617

18+
def apply_standard_pip_upgrades(
19+
function: Callable[[Session], Any]
20+
) -> Callable[[Session], Any]:
21+
@functools.wraps(function)
22+
def wrapper(session: Session) -> None:
23+
session.install("--upgrade", "pip", "setuptools", "wheel")
24+
return function(session)
25+
26+
return wrapper
27+
28+
1729
@nox.session(reuse_venv=True)
30+
@apply_standard_pip_upgrades
1831
def format(session: Session) -> None:
1932
install_requirements_file(session, "check-style")
2033
session.run("black", ".")
2134
session.run("isort", ".")
2235

2336

2437
@nox.session(reuse_venv=True)
38+
@apply_standard_pip_upgrades
2539
def example(session: Session) -> None:
2640
"""Run an example"""
2741
if not session.posargs:
@@ -36,6 +50,7 @@ def example(session: Session) -> None:
3650

3751

3852
@nox.session(reuse_venv=True)
53+
@apply_standard_pip_upgrades
3954
def docs(session: Session) -> None:
4055
"""Build and display documentation in the browser (automatically reloads on change)"""
4156
install_requirements_file(session, "build-docs")
@@ -85,29 +100,33 @@ def docs_in_docker(session: Session) -> None:
85100
@nox.session
86101
def test(session: Session) -> None:
87102
"""Run the complete test suite"""
88-
session.install("--upgrade", "pip", "setuptools", "wheel")
89-
test_suite(session)
90-
test_types(session)
91-
test_style(session)
92-
test_docs(session)
103+
session.notify("test_suite", posargs=session.posargs)
104+
session.notify("test_types")
105+
session.notify("test_style")
106+
session.notify("test_docs")
93107

94108

95109
@nox.session
110+
@apply_standard_pip_upgrades
96111
def test_suite(session: Session) -> None:
97112
"""Run the Python-based test suite"""
98113
session.env["IDOM_DEBUG_MODE"] = "1"
99114
install_requirements_file(session, "test-env")
100115

101-
pytest_args = get_posargs("pytest", session)
102-
if "--no-cov" in pytest_args:
116+
posargs = session.posargs
117+
if "--no-cov" in session.posargs:
118+
session.log("Coverage won't be checked")
103119
session.install(".[all]")
104120
else:
121+
session.log("Coverage will be checked")
122+
posargs += ["--cov=src/idom", "--cov-report", "term"]
105123
install_idom_dev(session, extras="all")
106124

107-
session.run("pytest", "tests", *pytest_args)
125+
session.run("pytest", "tests", *posargs)
108126

109127

110128
@nox.session
129+
@apply_standard_pip_upgrades
111130
def test_types(session: Session) -> None:
112131
"""Perform a static type analysis of the codebase"""
113132
install_requirements_file(session, "check-types")
@@ -117,6 +136,7 @@ def test_types(session: Session) -> None:
117136

118137

119138
@nox.session
139+
@apply_standard_pip_upgrades
120140
def test_style(session: Session) -> None:
121141
"""Check that style guidelines are being followed"""
122142
install_requirements_file(session, "check-style")
@@ -133,6 +153,7 @@ def test_style(session: Session) -> None:
133153

134154

135155
@nox.session
156+
@apply_standard_pip_upgrades
136157
def test_docs(session: Session) -> None:
137158
"""Verify that the docs build and that doctests pass"""
138159
install_requirements_file(session, "build-docs")
@@ -173,29 +194,6 @@ def parse_commit_reference(commit_ref: str) -> Tuple[str, str, str]:
173194
print(f"- {msg} - {sha_repr}")
174195

175196

176-
def get_posargs(name: str, session: Session) -> List[str]:
177-
"""Find named positional arguments
178-
179-
Positional args of the form `name[arg1,arg2]` will be parsed as ['arg1', 'arg2'] if
180-
the given `name` matches. Any args not matching that pattern will be added to the
181-
list of args as well. Thus the following:
182-
183-
--param session_1[arg1,arg2] session_2[arg3,arg4]
184-
185-
where `name` is session_1 would produce ['--param', 'arg1', 'arg2']
186-
"""
187-
collected_args: List[str] = []
188-
for arg in session.posargs:
189-
match = POSARGS_PATTERN.match(arg)
190-
if match is not None:
191-
found_name, found_args = match.groups()
192-
if name == found_name:
193-
collected_args.extend(map(str.strip, found_args.split(",")))
194-
else:
195-
collected_args.append(arg)
196-
return collected_args
197-
198-
199197
def install_requirements_file(session: Session, name: str) -> None:
200198
file_path = HERE / "requirements" / (name + ".txt")
201199
assert file_path.exists(), f"requirements file {file_path} does not exist"

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ exclude =
2020
[tool:pytest]
2121
testpaths = tests
2222
xfail_strict = True
23-
addopts = --cov=src/idom --cov-report term
2423
markers =
2524
slow: marks tests as slow (deselect with '-m "not slow"')
2625

0 commit comments

Comments
 (0)