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

tests: set PYTHONPATH via session scoped fixture #271

Merged
merged 3 commits into from
Mar 9, 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
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ universal = 1

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

[tool:pytest]
testpaths = tests
Expand Down
25 changes: 22 additions & 3 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ def test_foo(cov):
xdist_params = pytest.mark.parametrize('opts', ['', '-n 1'], ids=['nodist', 'xdist'])


@pytest.fixture(scope='session', autouse=True)
def adjust_sys_path():
"""Adjust PYTHONPATH during tests to make "helper" importable in SCRIPT."""
orig_path = os.environ.get('PYTHONPATH', None)
new_path = os.path.dirname(__file__)
if orig_path is not None:
new_path = os.pathsep.join([new_path, orig_path])
os.environ['PYTHONPATH'] = new_path

yield

if orig_path is None:
del os.environ['PYTHONPATH']
else:
os.environ['PYTHONPATH'] = orig_path


@pytest.fixture(params=[
('branch=true', '--cov-branch', '9 * 85%', '3 * 100%'),
('branch=true', '', '9 * 85%', '3 * 100%'),
Expand Down Expand Up @@ -450,7 +467,8 @@ def test_subprocess_with_path_aliasing(testdir, monkeypatch):
parallel = true
""")

monkeypatch.setitem(os.environ, 'PYTHONPATH', os.pathsep.join([os.environ.get('PYTHONPATH',''), 'aliased']))
monkeypatch.setitem(os.environ, 'PYTHONPATH', os.pathsep.join([
os.environ.get('PYTHONPATH', ''), 'aliased']))
result = testdir.runpytest('-v',
'--cov',
'--cov-report=term-missing',
Expand Down Expand Up @@ -1112,6 +1130,7 @@ def test_run():
])
assert result.ret == 0


@pytest.mark.skipif('sys.platform == "win32"', reason="fork not available on Windows")
def test_cleanup_on_sigterm_sig_ign(testdir):
script = testdir.makepyfile('''
Expand Down Expand Up @@ -1235,7 +1254,7 @@ def test_no_cover_marker(testdir):
@pytest.mark.no_cover
def test_basic():
mod.func()
subprocess.check_call([sys.executable, '-c', 'from mod import func; func()'])
subprocess.check_call([sys.executable, '-c', 'from mod import func; func()'])
''')
result = testdir.runpytest('-v', '-ra', '--strict',
'--cov=%s' % script.dirpath(),
Expand All @@ -1254,7 +1273,7 @@ def test_no_cover_fixture(testdir):

def test_basic(no_cover):
mod.func()
subprocess.check_call([sys.executable, '-c', 'from mod import func; func()'])
subprocess.check_call([sys.executable, '-c', 'from mod import func; func()'])
''')
result = testdir.runpytest('-v', '-ra', '--strict',
'--cov=%s' % script.dirpath(),
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ basepython =
py37: {env:TOXPYTHON:python3.7}
{clean,check,report,extension-coveralls,coveralls,spell}: python3.4
setenv =
PYTHONPATH={toxinidir}/tests
PYTHONUNBUFFERED=yes
passenv =
*
Expand Down