diff options
author | Bruno Oliveira <nicoddemus@gmail.com> | 2015-07-23 21:48:59 -0300 |
---|---|---|
committer | Bruno Oliveira <nicoddemus@gmail.com> | 2015-07-23 23:21:07 -0300 |
commit | ab9e246ab068d35330f2854acaacf49c24fa6920 (patch) | |
tree | cfe525f4f7b1d1b0ac3d9915fc872130a3a78c63 /testing/test_conftest.py | |
parent | df29120abe7d68ef955d4fe4eeb766b681648524 (diff) | |
download | pytest-ab9e246ab068d35330f2854acaacf49c24fa6920.tar.gz |
Avoid detecting conftest files upwards from setup.cfg/pytest.ini/tox.ini files by default
As discussed in #82
Diffstat (limited to 'testing/test_conftest.py')
-rw-r--r-- | testing/test_conftest.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/testing/test_conftest.py b/testing/test_conftest.py index 513ba43a5..64fa6d5e5 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -343,3 +343,44 @@ class TestConftestVisibility: with dirs[chdir].as_cwd(): reprec = testdir.inline_run(testarg, "-q", "--traceconfig") reprec.assertoutcome(passed=expect_ntests_passed) + + +@pytest.mark.parametrize('confcutdir,passed,error', [ + ('.', 2, 0), + ('src', 1, 1), + (None, 1, 1), +]) +def test_search_conftest_up_to_inifile(testdir, confcutdir, passed, error): + """Test that conftest files are detected only up to a ini file, unless + an explicit --confcutdir option is given. + """ + root = testdir.tmpdir + src = root.join('src').ensure(dir=1) + src.join('pytest.ini').write('[pytest]') + src.join('conftest.py').write(py.code.Source(""" + import pytest + @pytest.fixture + def fix1(): pass + """)) + src.join('test_foo.py').write(py.code.Source(""" + def test_1(fix1): + pass + def test_2(out_of_reach): + pass + """)) + root.join('conftest.py').write(py.code.Source(""" + import pytest + @pytest.fixture + def out_of_reach(): pass + """)) + + args = [str(src)] + if confcutdir: + args = ['--confcutdir=%s' % root.join(confcutdir)] + result = testdir.runpytest(*args) + match = '' + if passed: + match += '*%d passed*' % passed + if error: + match += '*%d error*' % error + result.stdout.fnmatch_lines(match) |