Skip to content

Commit

Permalink
test: don't run python 2.7 virtualenv tests for newer versions of vir…
Browse files Browse the repository at this point in the history
…tualenv (#702)

* Don't run python 2.7 virtualenv tests for newer versions of virtualenv
* exercise inner functions to ensure coverage if we can't run python 2.7 tests.
* fix lint, remove Unused type: ignore[no-any-return, no-untyped-call] comment
  • Loading branch information
crwilcox authored Apr 22, 2023
1 parent 119fd00 commit 0dd1a51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nox/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class InvalidVersionSpecifier(Exception):

def get_nox_version() -> str:
"""Return the version of the installed Nox package."""
return metadata.version("nox") # type: ignore[no-untyped-call, no-any-return]
return metadata.version("nox")


def _parse_string_constant(node: ast.AST) -> str | None: # pragma: no cover
Expand Down
30 changes: 30 additions & 0 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
from unittest import mock

import pytest
import virtualenv
from packaging import version

import nox.virtualenv

IS_WINDOWS = nox.virtualenv._SYSTEM == "Windows"
HAS_CONDA = shutil.which("conda") is not None
RAISE_ERROR = "RAISE_ERROR"
VIRTUALENV_VERSION = virtualenv.version.version


class TextProcessResult(NamedTuple):
Expand Down Expand Up @@ -472,6 +475,33 @@ def test_create_reuse_oldstyle_virtualenv_environment(make_one):


@enable_staleness_check
@pytest.mark.skipif(IS_WINDOWS, reason="Avoid 'No pyvenv.cfg file' error on Windows.")
def test_inner_functions_reusing_venv(make_one):
venv, location = make_one(reuse_existing=True)
venv.create()

# Drop a venv-style pyvenv.cfg into the environment.
pyvenv_cfg = """\
home = /usr/bin
include-system-site-packages = false
version = 3.10
base-prefix = foo
"""
location.join("pyvenv.cfg").write(dedent(pyvenv_cfg))

base_prefix = venv._read_base_prefix_from_pyvenv_cfg()
assert base_prefix == "foo"

reused_interpreter = venv._check_reused_environment_interpreter()
# The created won't match 'foo'
assert not reused_interpreter


@enable_staleness_check
@pytest.mark.skipif(
version.parse(VIRTUALENV_VERSION) >= version.parse("20.22.0"),
reason="Python 2.7 unsupported for virtualenv>=20.22.0",
)
def test_create_reuse_python2_environment(make_one):
venv, location = make_one(reuse_existing=True, interpreter="2.7")

Expand Down

0 comments on commit 0dd1a51

Please sign in to comment.