blob: a5a172e0f98aba374f3edc3db79cc83d17340c5e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
import contextlib
import sys
import shutil
import subprocess
import pytest
from . import contexts
@pytest.fixture
def user_override(monkeypatch):
"""
Override site.USER_BASE and site.USER_SITE with temporary directories in
a context.
"""
with contexts.tempdir() as user_base:
monkeypatch.setattr('site.USER_BASE', user_base)
with contexts.tempdir() as user_site:
monkeypatch.setattr('site.USER_SITE', user_site)
with contexts.save_user_site_setting():
yield
@pytest.fixture
def tmpdir_cwd(tmpdir):
with tmpdir.as_cwd() as orig:
yield orig
@pytest.fixture
def tmp_src(request, tmp_path):
"""Make a copy of the source dir under `$tmp/src`.
This fixture is useful whenever it's necessary to run `setup.py`
or `pip install` against the source directory when there's no
control over the number of simultaneous invocations. Such
concurrent runs create and delete directories with the same names
under the target directory and so they influence each other's runs
when they are not being executed sequentially.
"""
tmp_src_path = tmp_path / 'src'
shutil.copytree(request.config.rootdir, tmp_src_path)
return tmp_src_path
@pytest.fixture(autouse=True, scope="session")
def workaround_xdist_376(request):
"""
Workaround pytest-dev/pytest-xdist#376
``pytest-xdist`` tends to inject '' into ``sys.path``,
which may break certain isolation expectations.
Remove the entry so the import
machinery behaves the same irrespective of xdist.
"""
if not request.config.pluginmanager.has_plugin('xdist'):
return
with contextlib.suppress(ValueError):
sys.path.remove('')
@pytest.fixture
def sample_project(tmp_path):
"""
Clone the 'sampleproject' and return a path to it.
"""
cmd = ['git', 'clone', 'https://github.com/pypa/sampleproject']
try:
subprocess.check_call(cmd, cwd=str(tmp_path))
except Exception:
pytest.skip("Unable to clone sampleproject")
return tmp_path / 'sampleproject'
|