Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't run python 2.7 virtualenv tests for newer versions of virtualenv #702

Merged
merged 7 commits into from
Apr 22, 2023
Merged
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
Copy link

@stefanor stefanor May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's only available in recent versions of virtualenv, using hatch-vcs.

A quick dig didn't show me exactly what made it change, but in older versions, the path was: virtualenv.__version__ (which is still available today)



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