Skip to content

Commit

Permalink
chore: fix issue with tests
Browse files Browse the repository at this point in the history
Got rid of venv_location tests that created folder in home directory
  • Loading branch information
wpk committed Feb 27, 2024
1 parent ea8e444 commit 3c8949e
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,28 @@ def test_create_tmp_twice(self):
assert tmpdir.startswith(root)

@pytest.mark.parametrize("pre_run", [0, 1])
def test_create_tmp_with_venv_location(self, change_to_tmp_path, pre_run):
def test_create_tmp_with_venv_location(self, pre_run):
# for testing, also set envdir
with tempfile.TemporaryDirectory() as new_location:
session, runner = self.make_session_and_runner(
venv_location=os.path.join(new_location, "my-location")
)
# for testing, also set envdir
with tempfile.TemporaryDirectory() as root:
runner.global_config.envdir = root
for _ in range(pre_run):
session.create_tmp()

tmpdir = session.create_tmp()

assert tmpdir == os.path.join(new_location, "my-location", "tmp")
assert os.path.abspath(tmpdir) == os.path.join(
new_location, "my-location", "tmp"
)
assert session.env["TMPDIR"] == os.path.abspath(tmpdir)

@pytest.mark.parametrize("pre_run", [0, 1])
def test_create_tmp_with_venv_location2(self, change_to_tmp_path, pre_run):
session, runner = self.make_session_and_runner(venv_location="my-location")
# for testing, also set envdir
with tempfile.TemporaryDirectory() as root:
Expand All @@ -126,21 +147,16 @@ def test_create_tmp_with_venv_location(self, change_to_tmp_path, pre_run):
)
assert session.env["TMPDIR"] == os.path.abspath(tmpdir)

@pytest.mark.parametrize("pre_run", [0, 1])
def test_create_tmp_with_venv_location_home_path(self, change_to_tmp_path, pre_run):
"""Test that this works with absolute path..."""
session, runner = self.make_session_and_runner(venv_location="~/my-location")
# for testing, also set envdir
with tempfile.TemporaryDirectory() as root:
runner.global_config.envdir = root
for _ in range(pre_run):
session.create_tmp()

tmpdir = session.create_tmp()

assert tmpdir == os.path.join(os.path.expanduser("~/my-location"), "tmp")
assert tmpdir == os.path.abspath(tmpdir)
assert session.env["TMPDIR"] == os.path.abspath(tmpdir)
@pytest.mark.parametrize(
("venv_location", "envdir"),
[
("my-location", "my-location"),
("~/my-location", os.path.expanduser("~/my-location")),
],
)
def test_envdir(self, venv_location, envdir):
session, runner = self.make_session_and_runner(venv_location=venv_location)
assert runner.envdir == envdir

def test_properties(self):
session, runner = self.make_session_and_runner()
Expand Down Expand Up @@ -973,7 +989,7 @@ def test__create_venv(self, create):
assert runner.venv.interpreter is None
assert runner.venv.reuse_existing is False

@pytest.mark.parametrize("venv_location", [None, "my-location", "~/my-location"])
@pytest.mark.parametrize("venv_location", [None, "my-location"])
@pytest.mark.parametrize(
"create_method,venv_backend,expected_backend",
[
Expand Down Expand Up @@ -1016,9 +1032,6 @@ def test__create_venv_options(
assert runner.venv.location == os.path.abspath(location_name)
assert runner.envdir == location_name

if venv_location and "~/" in venv_location:
assert runner.venv.location_name == runner.venv.location

def test__create_venv_unexpected_venv_backend(self):
runner = self.make_runner()
runner.func.venv_backend = "somenewenvtool"
Expand Down

0 comments on commit 3c8949e

Please sign in to comment.