-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Isolate tests and run concurrently #1159
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
Changes from all commits
bd127f8
17cfdc5
f70b2a1
0c42245
f9a3b97
9bb20bd
c3f7a9c
d9c8452
5827fd1
5535300
45dc936
6b02bc7
9ed8c1a
bacf3a0
487925e
cb73080
1bd8dd9
1650d41
fe60a1d
99f520d
5fece08
946465b
86f5ebb
3095571
1ba1c70
4516a34
fab60dc
0cc93cc
67bd767
b9706a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,12 @@ before_install: | |
- echo -e "[web]\ncacerts = /etc/ssl/certs/ca-certificates.crt" >> ~/.hgrc | ||
- git config --global user.email "[email protected]" | ||
- git config --global user.name "Pip" | ||
install: pip install pytest git+https://github.com/pypa/virtualenv@develop#egg=virtualenv scripttest>=1.3 mock | ||
script: py.test | ||
install: | ||
- pip install --upgrade setuptools | ||
- pip install pytest pytest-xdist git+https://github.com/pypa/virtualenv@develop#egg=virtualenv scripttest>=1.3 mock | ||
script: | ||
- "if [[ $TRAVIS_PYTHON_VERSION == '3.2' ]]; then py.test -v; fi" | ||
- "if [[ $TRAVIS_PYTHON_VERSION != '3.2' ]]; then py.test -v -n 8; fi" | ||
notifications: | ||
irc: "irc.freenode.org#pip" | ||
branches: | ||
|
@@ -20,4 +24,4 @@ branches: | |
- 1.3.X | ||
- 1.4.X | ||
env: | ||
- PIP_USE_MIRRORS=true | ||
- PYTHONHASHSEED=0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where does this apply? 0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Python 3.3+ hash randomization is on by default, this confuses pytest-xdist. Setting the hash seed to zero effectively disables hash randomization. See https://bitbucket.org/hpk42/pytest/issue/346/pytest-xdist-and-python-33-is-sort-of |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import shutil | ||
|
||
import py | ||
import pytest | ||
|
||
from tests.lib import SRC_DIR, TestData | ||
from tests.lib.path import Path | ||
from tests.lib.scripttest import PipTestEnvironment | ||
from tests.lib.venv import VirtualEnvironment | ||
|
||
|
||
@pytest.fixture | ||
def tmpdir(request): | ||
""" | ||
Return a temporary directory path object which is unique to each test | ||
function invocation, created as a sub directory of the base temporary | ||
directory. The returned object is a ``tests.lib.path.Path`` object. | ||
|
||
This is taken from pytest itself but modified to return our typical | ||
path object instead of py.path.local. | ||
""" | ||
name = request.node.name | ||
name = py.std.re.sub("[\W]", "_", name) | ||
tmp = request.config._tmpdirhandler.mktemp(name, numbered=True) | ||
return Path(tmp) | ||
|
||
|
||
@pytest.fixture | ||
def virtualenv(tmpdir, monkeypatch): | ||
""" | ||
Return a virtual environment which is unique to each test function | ||
invocation created inside of a sub directory of the test function's | ||
temporary directory. The returned object is a | ||
``tests.lib.venv.VirtualEnvironment`` object. | ||
""" | ||
# Force shutil to use the older method of rmtree that didn't use the fd | ||
# functions. These seem to fail on Travis (and only on Travis). | ||
monkeypatch.setattr(shutil, "_use_fd_functions", False, raising=False) | ||
|
||
# Copy over our source tree so that each virtual environment is self | ||
# contained | ||
pip_src = tmpdir.join("pip_src").abspath | ||
shutil.copytree(SRC_DIR, pip_src, | ||
ignore=shutil.ignore_patterns( | ||
"*.pyc", "docs/", "tests/", "pip.egg-info", | ||
), | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wondering if we should build a wheel and install from that over and over. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. I did try building a sdist and installing from it and the increase in time was pretty noticeable. Right now we copy the directory into the temporary directory and then using |
||
|
||
# Create the virtual environment | ||
venv = VirtualEnvironment.create( | ||
tmpdir.join("workspace", "venv"), | ||
pip_source_dir=pip_src, | ||
) | ||
|
||
# Undo our monkeypatching of shutil | ||
monkeypatch.undo() | ||
|
||
return venv | ||
|
||
|
||
@pytest.fixture | ||
def script(tmpdir, virtualenv): | ||
""" | ||
Return a PipTestEnvironment which is unique to each test function and | ||
will execute all commands inside of the unique virtual environment for this | ||
test function. The returned object is a | ||
``tests.lib.scripttest.PipTestEnvironment``. | ||
""" | ||
return PipTestEnvironment( | ||
# The base location for our test environment | ||
tmpdir.join("workspace"), | ||
|
||
# Tell the Test Environment where our virtualenv is located | ||
virtualenv=virtualenv.location, | ||
|
||
# Do not ignore hidden files, they need to be checked as well | ||
ignore_hidden=False, | ||
|
||
# We are starting with an already empty directory | ||
start_clear=False, | ||
|
||
# We want to ensure no temporary files are left behind, so the | ||
# PipTestEnvironment needs to capture and assert against temp | ||
capture_temp=True, | ||
assert_no_temp=True, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def data(tmpdir): | ||
return TestData.copy(tmpdir.join("data")) | ||
|
||
# This is here to work around a bug with pytest, pytest-xdist, and Python 3.2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The extra new lines and the comment itself. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, this actually works on travis.