Skip to content

Commit

Permalink
Change "tmpdir" fixture to work with latest pytest
Browse files Browse the repository at this point in the history
Re-using the built-in tmpdir fixture fixes pytest-dev/pytest#1083

Also with latest pytest there's no need to use --assert=plain on py35 anymore

Fixes pypa#3699
Fixes pytest-dev/pytest#1083
  • Loading branch information
nicoddemus committed Jul 22, 2016
1 parent 17df548 commit 7aa30db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
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

0 comments on commit 7aa30db

Please sign in to comment.