Skip to content

Commit 5c6058c

Browse files
authored
Merge pull request #271 from blueyed/pp
tests: set PYTHONPATH via session scoped fixture
2 parents 41eea2e + cbbfc7e commit 5c6058c

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ universal = 1
33

44
[flake8]
55
max-line-length = 140
6-
exclude = tests/*,*/migrations/*,*/south_migrations/*
76

87
[tool:pytest]
98
testpaths = tests

tests/test_pytest_cov.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,23 @@ def test_foo(cov):
156156
], ids=['nodist', 'xdist'])
157157

158158

159+
@pytest.fixture(scope='session', autouse=True)
160+
def adjust_sys_path():
161+
"""Adjust PYTHONPATH during tests to make "helper" importable in SCRIPT."""
162+
orig_path = os.environ.get('PYTHONPATH', None)
163+
new_path = os.path.dirname(__file__)
164+
if orig_path is not None:
165+
new_path = os.pathsep.join([new_path, orig_path])
166+
os.environ['PYTHONPATH'] = new_path
167+
168+
yield
169+
170+
if orig_path is None:
171+
del os.environ['PYTHONPATH']
172+
else:
173+
os.environ['PYTHONPATH'] = orig_path
174+
175+
159176
@pytest.fixture(params=[
160177
('branch=true', '--cov-branch', '9 * 85%', '3 * 100%'),
161178
('branch=true', '', '9 * 85%', '3 * 100%'),
@@ -454,7 +471,8 @@ def test_subprocess_with_path_aliasing(testdir, monkeypatch):
454471
parallel = true
455472
""")
456473

457-
monkeypatch.setitem(os.environ, 'PYTHONPATH', os.pathsep.join([os.environ.get('PYTHONPATH',''), 'aliased']))
474+
monkeypatch.setitem(os.environ, 'PYTHONPATH', os.pathsep.join([
475+
os.environ.get('PYTHONPATH', ''), 'aliased']))
458476
result = testdir.runpytest('-v',
459477
'--cov',
460478
'--cov-report=term-missing',

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ basepython =
1818
py37: {env:TOXPYTHON:python3.7}
1919
{clean,check,report,extension-coveralls,coveralls,spell}: python3.4
2020
setenv =
21-
PYTHONPATH={toxinidir}/tests
2221
PYTHONUNBUFFERED=yes
2322
passenv =
2423
*

0 commit comments

Comments
 (0)