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

Use native nox for tests (not @cs01 fork of nox) #512

Merged
merged 14 commits into from
Oct 3, 2020
7 changes: 5 additions & 2 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,16 @@ jobs:
# Build regex wheel into pip cache, so future pipx installs don't compile.
# This avoids future compile errors in nox tests because of missing
# header files.
# Inside a pytest session, tests/conftest.py removes all existing paths from
# the system PATH, which can cause C compilation to fail. So here we
# pre-build some packages' wheels outside of pytest.
- name: Install wheel and build wheel for regex to pip cache
if: ${{ runner.os == 'macOS' }}
run: |
python -m pip install wheel
python -m pip install regex
- name: Install native-venv version of nox
run: pip install --use-feature=2020-resolver git+https://github.com/cs01/nox.git@5ea70723e9e6#egg=nox
- name: Install nox
run: pip install nox
- name: Execute Tests
run: |
nox --non-interactive --session tests-${{ matrix.python-version }}
9 changes: 3 additions & 6 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ pipx uses an automation tool called [nox](https://pypi.org/project/nox/) for dev

Install nox for pipx development:
```
python -m pip install --user git+https://github.com/cs01/nox.git@5ea70723e9e6 nox
python -m pip install --user nox
```

!!! note
A specific version of nox must be used for pipx development until [nox issue 233](https://github.com/theacodes/nox/issues/233) is resolved.

Tests are defined as `nox` sessions. You can see all nox sessions with
```
nox -l
Expand Down Expand Up @@ -54,13 +51,13 @@ nox -s tests-3.7
```

!!! tip
You can running a specific unit test by passing arguments to pytest, the test runner pipx uses:
You can run a specific unit test by passing arguments to pytest, the test runner pipx uses:

```
nox -s tests-3.8 -- -k EXPRESSION
```

Expression can be a test name, such as
`EXPRESSION` can be a test name, such as

```
nox -s tests-3.8 -- -k test_uninstall
Expand Down
6 changes: 2 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
.PHONY: test docs develop build publish publish_docs lint

develop:
pipx run --spec=git+https://github.com/cs01/nox.git@5ea70723e9e6 nox -s develop
pipx run nox -s develop

lint:
pipx run nox -s lint

test:
# TODO use `pipx run nox` when nox supports venv creation (and thus
# pipx tests pass)
pipx run --spec=git+https://github.com/cs01/nox.git@5ea70723e9e6 nox
pipx run nox

publish:
pipx run nox -s publish-3.7
Expand Down
9 changes: 0 additions & 9 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@

import nox # type: ignore

# NOTE: these tests require nox to create virtual environments
# with venv. nox currently uses virtualenv. pipx
# uses a fork of nox at https://github.com/cs01/nox
# on the branch cs01/use-venv
# To invoke nox for pipx, use:
# pipx run --spec=git+https://github.com/cs01/nox.git@2ba8984a nox
# until this is fixed in nox. See
# https://github.com/theacodes/nox/issues/199

python = ["3.6", "3.7", "3.8"]

if sys.platform == "win32":
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ def pipx_temp_env(tmp_path, monkeypatch):
monkeypatch.setattr(constants, "PIPX_LOCAL_VENVS", home_dir / "venvs")
monkeypatch.setattr(constants, "PIPX_VENV_CACHEDIR", home_dir / ".cache")

# TODO: macOS needs /usr/bin in PATH to compile certain packages, but
# applications in /usr/bin cause test_install.py tests to raise warnings
# which make tests fail (e.g. on Github ansible apps exist in /usr/bin)
monkeypatch.setenv("PATH", str(bin_dir))
6 changes: 1 addition & 5 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from shutil import which
import subprocess
import sys
from shutil import which
from typing import List
from unittest import mock

from pipx import main


def assert_not_in_virtualenv():
assert not hasattr(sys, "real_prefix"), "Tests cannot run under virtualenv"


def run_pipx_cli(pipx_args: List[str]):
with mock.patch.object(sys, "argv", ["pipx"] + pipx_args):
return main.cli()
Expand Down
5 changes: 1 addition & 4 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@

import pytest # type: ignore

from helpers import assert_not_in_virtualenv, run_pipx_cli, which_python
from helpers import run_pipx_cli, which_python
from pipx import constants

assert_not_in_virtualenv()


PYTHON3_5 = which_python("python3.5")


Expand Down
4 changes: 1 addition & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

import pytest # type: ignore

from helpers import assert_not_in_virtualenv, run_pipx_cli
from helpers import run_pipx_cli
from pipx import main

assert_not_in_virtualenv()


def test_help_text(monkeypatch, capsys):
mock_exit = mock.Mock(side_effect=ValueError("raised in test to exit early"))
Expand Down
5 changes: 1 addition & 4 deletions tests/test_pipx_metadata_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import pytest # type: ignore

import pipx.constants
from helpers import assert_not_in_virtualenv, run_pipx_cli
from helpers import run_pipx_cli
from pipx.pipx_metadata_file import PackageInfo, PipxMetadata
from pipx.util import PipxError

assert_not_in_virtualenv()


TEST_PACKAGE1 = PackageInfo(
package="test_package",
package_or_url="test_package_url",
Expand Down