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

Improve automated tests support on Windows #300

Merged
merged 9 commits into from
Mar 8, 2021
6 changes: 2 additions & 4 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ def __init__(
@property
def bin(self) -> str:
"""Returns the location of the conda env's bin folder."""
if _SYSTEM == "Windows":
return os.path.join(self.location, "Scripts")
else:
return os.path.join(self.location, "bin")
bin_folder = "Scripts" if _SYSTEM == "Windows" else "bin"
return os.path.join(self.location, bin_folder)

def create(self) -> bool:
"""Create the conda env."""
Expand Down
14 changes: 11 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import shutil

import nox

Expand All @@ -37,7 +38,13 @@ def tests(session):
session.run("pytest", *tests)
return
session.run(
"pytest", "--cov=nox", "--cov-config", ".coveragerc", "--cov-report=", *tests
"pytest",
"--cov=nox",
"--cov-config",
".coveragerc",
"--cov-report=",
*tests,
env={"COVERAGE_FILE": ".coverage.{}".format(session.python)}
)
session.notify("cover")

Expand All @@ -62,6 +69,7 @@ def cover(session):
fail_under = "--fail-under=99"
else:
fail_under = "--fail-under=100"
session.run("coverage", "combine")
session.run("coverage", "report", fail_under, "--show-missing")
session.run("coverage", "erase")

Expand Down Expand Up @@ -90,10 +98,10 @@ def lint(session):
session.run("flake8", "nox", *files)


@nox.session(python="3.8")
@nox.session(python="3.7")
def docs(session):
"""Build the documentation."""
session.run("rm", "-rf", "docs/_build", external=True)
shutil.rmtree("docs/_build", ignore_errors=True)
session.install("-r", "requirements-test.txt")
session.install(".")
session.cd("docs")
Expand Down
23 changes: 16 additions & 7 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,18 @@ def test_condaenv_create(make_conda):
assert dir_.join("test.txt").check()


@pytest.mark.skipif(IS_WINDOWS, reason="Not testing multiple interpreters on Windows.")
@pytest.mark.skipif(not HAS_CONDA, reason="Missing conda command.")
def test_condaenv_create_interpreter(make_conda):
venv, dir_ = make_conda(interpreter="3.7")
venv.create()
assert dir_.join("bin", "python").check()
assert dir_.join("bin", "python3.7").check()
if IS_WINDOWS:
assert dir_.join("python.exe").check()
assert dir_.join("python37.dll").check()
assert dir_.join("python37.pdb").check()
assert not dir_.join("python37.exe").check()
else:
assert dir_.join("bin", "python").check()
assert dir_.join("bin", "python3.7").check()


@mock.patch("nox.virtualenv._SYSTEM", new="Windows")
Expand Down Expand Up @@ -296,12 +301,16 @@ def test_create_venv_backend(make_one):
venv.create()


@pytest.mark.skipif(IS_WINDOWS, reason="Not testing multiple interpreters on Windows.")
def test_create_interpreter(make_one):
venv, dir_ = make_one(interpreter="python3")
interpreter = "3.7" if IS_WINDOWS else "python3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this work regardless of which Python version we're testing with?

venv, dir_ = make_one(interpreter=interpreter)
venv.create()
assert dir_.join("bin", "python").check()
assert dir_.join("bin", "python3").check()
if IS_WINDOWS:
assert dir_.join("Scripts", "python.exe").check()
assert not dir_.join("Scripts", "python37.exe").check()
else:
assert dir_.join("bin", "python").check()
assert dir_.join("bin", "python3").check()


def test__resolved_interpreter_none(make_one):
Expand Down