diff --git a/setup.cfg b/setup.cfg index 5fc43b51..7de4bad2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,6 @@ universal = 1 [flake8] max-line-length = 140 -exclude = tests/*,*/migrations/*,*/south_migrations/* [tool:pytest] testpaths = tests diff --git a/tests/test_pytest_cov.py b/tests/test_pytest_cov.py index 8809eaed..bac073ed 100644 --- a/tests/test_pytest_cov.py +++ b/tests/test_pytest_cov.py @@ -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%'), @@ -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', @@ -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(''' @@ -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(), @@ -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(), diff --git a/tox.ini b/tox.ini index 8b15169f..dc80c8b7 100644 --- a/tox.ini +++ b/tox.ini @@ -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 = *