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

Share script fixtures across tests #7276

Merged
merged 6 commits into from
Nov 2, 2019
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
74 changes: 48 additions & 26 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,52 +272,69 @@ def virtualenv_template(request, tmpdir_factory, pip_src,
yield venv


@pytest.fixture(scope="session")
def virtualenv_factory(virtualenv_template):
def factory(tmpdir):
return VirtualEnvironment(tmpdir, virtualenv_template)

return factory


@pytest.fixture
def virtualenv(virtualenv_template, tmpdir, isolate):
def virtualenv(virtualenv_factory, tmpdir):
"""
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.
"""
venv_location = tmpdir.joinpath("workspace", "venv")
yield VirtualEnvironment(venv_location, virtualenv_template)
yield virtualenv_factory(tmpdir.joinpath("workspace", "venv"))


@pytest.fixture
def with_wheel(virtualenv, wheel_install):
install_egg_link(virtualenv, 'wheel', wheel_install)


@pytest.fixture(scope="session")
def script_factory(virtualenv_factory, deprecated_python):
def factory(tmpdir, virtualenv=None):
if virtualenv is None:
virtualenv = virtualenv_factory(tmpdir.joinpath("venv"))
return PipTestEnvironment(
# The base location for our test environment
tmpdir,

# Tell the Test Environment where our virtualenv is located
virtualenv=virtualenv,

# 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,

# Deprecated python versions produce an extra deprecation warning
pip_expect_warning=deprecated_python,
)

return factory


@pytest.fixture
def script(tmpdir, virtualenv, deprecated_python):
def script(tmpdir, virtualenv, script_factory):
"""
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.joinpath("workspace"),

# Tell the Test Environment where our virtualenv is located
virtualenv=virtualenv,

# 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,

# Deprecated python versions produce an extra deprecation warning
pip_expect_warning=deprecated_python,
)
return script_factory(tmpdir.joinpath("workspace"), virtualenv)


@pytest.fixture(scope="session")
Expand All @@ -326,6 +343,11 @@ def common_wheels():
return DATA_DIR.joinpath('common_wheels')


@pytest.fixture(scope="session")
def shared_data(tmpdir_factory):
return TestData.copy(Path(str(tmpdir_factory.mktemp("data"))))


@pytest.fixture
def data(tmpdir):
return TestData.copy(tmpdir.joinpath("data"))
Expand Down Expand Up @@ -359,7 +381,7 @@ def in_memory_pip():
return InMemoryPip()


@pytest.fixture
@pytest.fixture(scope="session")
def deprecated_python():
"""Used to indicate whether pip deprecated this python version"""
return sys.version_info[:2] in [(2, 7)]
Loading