Skip to content

Commit

Permalink
Fix pytest on macOS in Travis (certbot#5360)
Browse files Browse the repository at this point in the history
* Add tools/pytest.sh

* pass TRAVIS through in tox.ini

* Use tools/pytest.sh to run pytest

* Add quiet to pytest.ini

* ignore pytest cache
  • Loading branch information
bmw authored and ohemorange committed Jan 4, 2018
1 parent ed2168a commit 5388842
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ tests/letstest/*.pem
tests/letstest/venv/

.venv

# pytest cache
/.cache
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --quiet
2 changes: 1 addition & 1 deletion tools/install_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ for requirement in "$@" ; do
# See https://travis-ci.org/certbot/certbot/jobs/308774157#L1333.
pkg=$(echo "$pkg" | tr - _)
fi
pytest --numprocesses auto --quiet --pyargs $pkg
"$(dirname $0)/pytest.sh" --pyargs $pkg
done
15 changes: 15 additions & 0 deletions tools/pytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# Runs pytest with the provided arguments, adding --numprocesses to the command
# line. This argument is set to "auto" if the environmnent variable TRAVIS is
# not set, otherwise, it is set to 2. This works around
# https://github.com/pytest-dev/pytest-xdist/issues/9. Currently every Travis
# environnment provides two cores. See
# https://docs.travis-ci.com/user/reference/overview/#Virtualization-environments.

if ${TRAVIS:-false}; then
NUMPROCESSES="2"
else
NUMPROCESSES="auto"
fi

pytest --numprocesses "$NUMPROCESSES" "$@"
3 changes: 2 additions & 1 deletion tox.cover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ cover () {
fi

pkg_dir=$(echo "$1" | tr _ -)
pytest --cov "$pkg_dir" --cov-append --cov-report= --numprocesses auto --pyargs "$1"
pytest="$(dirname $0)/tools/pytest.sh"
"$pytest" --cov "$pkg_dir" --cov-append --cov-report= --pyargs "$1"
coverage report --fail-under="$min" --include="$pkg_dir/*" --show-missing
}

Expand Down
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ commands =
deps =
setuptools==36.8.0
wheel==0.29.0
passenv = TRAVIS

[testenv]
commands =
Expand All @@ -69,19 +70,25 @@ commands =
setenv =
PYTHONPATH = {toxinidir}
PYTHONHASHSEED = 0
passenv =
{[testenv:py26]passenv}

[testenv:py33]
commands =
{[testenv]commands}
deps =
wheel==0.29.0
passenv =
{[testenv]passenv}

[testenv:py27-oldest]
commands =
{[testenv]commands}
setenv =
{[testenv]setenv}
CERTBOT_OLDEST=1
passenv =
{[testenv]passenv}

[testenv:py27_install]
basepython = python2.7
Expand All @@ -93,6 +100,8 @@ basepython = python2.7
commands =
{[base]install_packages}
./tox.cover.sh
passenv =
{[testenv]passenv}

[testenv:lint]
# recent versions of pylint do not support Python 2.6 (#97, #187)
Expand Down

0 comments on commit 5388842

Please sign in to comment.