Skip to content

Change "tmpdir" fixture to work with latest pytest #3863

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

Merged
merged 1 commit into from
Jul 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions .travis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
set -e
set -x

# If we're running under Python 3.5, we can't use anything but --asert=plain
if [[ $TOXENV = "py35" ]]; then
export TOXARGS="--assert=plain"
fi

# If we're running under Python 3.6, we can't use anything but --asert=plain
if [[ $TOXENV = "py36" ]]; then
export TOXARGS="--assert=plain"
fi

# We want to create the virtual environment here, but not actually run anything
tox --notest

Expand Down Expand Up @@ -51,7 +41,7 @@ if [[ $VENDOR = "no" ]]; then
fi

# Run the unit tests
tox -- -m unit $TOXARGS
tox -- -m unit

# Run our integration tests
tox -- -m integration -n 8 $TOXARGS
tox -- -m integration -n 8
6 changes: 2 additions & 4 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
freezegun
pretend
# Pinned to 2.7.2 to avoid an issue with parallel builds
pytest==2.7.2
pytest
pytest-capturelog
# Pinned to 0.5 to stay compatible with pytest==2.7.2
pytest-timeout==0.5
pytest-timeout
pytest-xdist
mock<1.1
scripttest>=1.3
Expand Down
21 changes: 8 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import shutil

import py
import pytest

from pip.utils import appdirs
Expand Down Expand Up @@ -42,27 +41,23 @@ def pytest_collection_modifyitems(items):
)


@pytest.fixture
def tmpdir(request):
@pytest.yield_fixture
def tmpdir(tmpdir):
"""
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 as well as deleting the temporary
directories at the end of each test case.
This uses the built-in tmpdir fixture from pytest itself but modified
to return our typical path object instead of py.path.local as well as
deleting the temporary directories at the end of each test case.
"""
name = request.node.name
name = py.std.re.sub("[\W]", "_", name)
tmp = request.config._tmpdirhandler.mktemp(name, numbered=True)

assert tmpdir.isdir()
yield Path(str(tmpdir))
# Clear out the temporary directory after the test has finished using it.
# This should prevent us from needing a multiple gigabyte temporary
# directory while running the tests.
request.addfinalizer(lambda: shutil.rmtree(str(tmp), ignore_errors=True))

return Path(str(tmp))
tmpdir.remove(ignore_errors=True)


@pytest.fixture(autouse=True)
Expand Down