Skip to content

Commit 6c9f43e

Browse files
committed
Extract nox session to conftest.py
1 parent 34fc607 commit 6c9f43e

File tree

2 files changed

+56
-43
lines changed

2 files changed

+56
-43
lines changed

test/unit/nox/_artifacts_test.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from dataclasses import dataclass
66
from inspect import cleandoc
77
from pathlib import Path
8-
from typing import Any
98
from unittest import mock
109
from unittest.mock import (
1110
Mock,
@@ -14,14 +13,7 @@
1413
)
1514

1615
import pytest
17-
from nox import (
18-
Session,
19-
_options,
20-
manifest,
21-
virtualenv,
22-
)
2316
from nox.sessions import (
24-
SessionRunner,
2517
_SessionQuit,
2618
)
2719

@@ -319,41 +311,6 @@ def test_all_files(tmp_path, capsys):
319311
assert (tmp_path / f).exists()
320312

321313

322-
class FakeEnv(mock.MagicMock):
323-
# Extracted from nox testing
324-
_get_env = virtualenv.VirtualEnv._get_env
325-
326-
327-
def make_fake_env(venv_backend: str = "venv", **kwargs: Any) -> FakeEnv:
328-
# Extracted from nox testing
329-
return FakeEnv(
330-
spec=virtualenv.VirtualEnv,
331-
env={},
332-
venv_backend=venv_backend,
333-
**kwargs,
334-
)
335-
336-
337-
@pytest.fixture
338-
def nox_session(tmp_path):
339-
# Extracted from nox testing
340-
session_runner = SessionRunner(
341-
name="test",
342-
signatures=["test"],
343-
func=mock.Mock(spec=["python"], python="3.10"),
344-
global_config=_options.options.namespace(
345-
posargs=[],
346-
error_on_external_run=False,
347-
install_only=False,
348-
invoked_from=tmp_path,
349-
),
350-
manifest=mock.create_autospec(manifest.Manifest),
351-
)
352-
session_runner.venv = make_fake_env(bin_paths=["/no/bin/for/you"])
353-
session = Session(session_runner)
354-
yield session
355-
356-
357314
class TestPrepareCoverageXml:
358315
@staticmethod
359316
def test_no_coverage_file_silently_passes(monkeypatch, tmp_path, nox_session):

test/unit/nox/conftest.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from typing import Any
2+
from unittest import mock
3+
4+
import pytest
5+
from nox import (
6+
Session,
7+
_options,
8+
manifest,
9+
virtualenv,
10+
)
11+
from nox.sessions import (
12+
SessionRunner,
13+
)
14+
15+
16+
class FakeEnv(mock.MagicMock):
17+
# Extracted from nox testing
18+
_get_env = virtualenv.VirtualEnv._get_env
19+
20+
21+
def make_fake_env(venv_backend: str = "venv", **kwargs: Any) -> FakeEnv:
22+
# Extracted from nox testing
23+
return FakeEnv(
24+
spec=virtualenv.VirtualEnv,
25+
env={},
26+
venv_backend=venv_backend,
27+
**kwargs,
28+
)
29+
30+
31+
@pytest.fixture
32+
def nox_session_runner_posargs() -> list[str]:
33+
return []
34+
35+
36+
@pytest.fixture
37+
def nox_session_runner(tmp_path, nox_session_runner_posargs):
38+
return SessionRunner(
39+
name="test",
40+
signatures=["test"],
41+
func=mock.Mock(spec=["python"], python="3.10"),
42+
global_config=_options.options.namespace(
43+
posargs=nox_session_runner_posargs,
44+
error_on_external_run=False,
45+
install_only=False,
46+
invoked_from=tmp_path,
47+
),
48+
manifest=mock.create_autospec(manifest.Manifest),
49+
)
50+
51+
52+
@pytest.fixture
53+
def nox_session(nox_session_runner):
54+
# Extracted from nox testing
55+
nox_session_runner.venv = make_fake_env(bin_paths=["/no/bin/for/you"])
56+
yield Session(nox_session_runner)

0 commit comments

Comments
 (0)