Skip to content

Commit

Permalink
Do not set TMPDIR when exporting to requirements.txt (#298)
Browse files Browse the repository at this point in the history
* Do not set TMPDIR when exporting to requirements.txt

* Adapt unit tests

* Remove obsolete workaround from #178

* Workaround an issue in Nox's types
  • Loading branch information
cjolowicz authored Mar 14, 2021
1 parent a68f918 commit 1a000fe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def tests(session: Session) -> None:
session.install("dataclasses")

try:
session.env.pop("TMPDIR", None)
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
finally:
if session.interactive:
Expand Down
4 changes: 3 additions & 1 deletion src/nox_poetry/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def export_requirements(self) -> Path:
Returns:
The path to the requirements file.
"""
tmpdir = Path(self.session.create_tmp())
tmpdir = Path(self.session.virtualenv.location) / "tmp"
tmpdir.mkdir(exist_ok=True)

path = tmpdir / "requirements.txt"
hashfile = tmpdir / f"{path.name}.hash"

Expand Down
15 changes: 9 additions & 6 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
from nox.sessions import Session


class FakeVirtualenv:
"""Fake virtual environment."""

def __init__(self, path: Path) -> None:
"""Initialize."""
self.location = str(path)


class FakeSession:
"""Fake session."""

def __init__(self, path: Path) -> None:
"""Initialize."""
self.path = path
self.virtualenv = FakeVirtualenv(path)

def run_always(self, *args: str, **kargs: Any) -> str:
"""Run."""
Expand All @@ -23,11 +31,6 @@ def run_always(self, *args: str, **kargs: Any) -> str:

def install(self, *args: str, **kargs: Any) -> None:
"""Install."""
pass

def create_tmp(self, *args: str, **kargs: Any) -> str:
"""Create temporary directory."""
return str(self.path)


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def proxy(session: nox.Session) -> nox_poetry.Session:

def test_session_getattr(proxy: nox_poetry.Session) -> None:
"""It delegates to the real session."""
assert proxy.create_tmp()
# Fixed in https://github.com/theacodes/nox/pull/377
assert proxy.virtualenv.location # type: ignore[attr-defined]


def test_session_install(proxy: nox_poetry.Session) -> None:
Expand Down

0 comments on commit 1a000fe

Please sign in to comment.