Skip to content

Commit 5e72c2e

Browse files
pilou-philpep
authored andcommitted
Allow to execute test_invocation from sources
without testinfra being installed, using for example: PYTHONPATH=. pytest test/test_invocation.py Fix this issue: =============================== FAILURES =============================== __________________________ test_nagios_notest __________________________ testdir = <Testdir local('/tmp/pytest-of-pilou/pytest/test_nagios_notest0')> def test_nagios_notest(testdir): result = testdir.runpytest('--nagios', '-q', '--tb=no') > assert result.ret == 0 E assert 4 == 0 E + where 4 = <RunResult ret=4 len(stdout.lines)=1 len(stderr.lines)=6 duration=0.06s>.ret src/testinfra/test/test_invocation.py:18: AssertionError ------------------------- Captured stderr call ------------------------- ERROR: usage: pytest-3 [options] [file_or_dir] [file_or_dir] [...] pytest-3: error: unrecognized arguments: --nagios inifile: None rootdir: /tmp/pytest-of-pilou/pytest/test_nagios_notest0
1 parent eeb149b commit 5e72c2e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

test/test_invocation.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,34 @@
1313
pytest_plugins = ['pytester']
1414

1515

16-
def test_nagios_notest(testdir):
17-
result = testdir.runpytest('--nagios', '-q', '--tb=no')
16+
def test_nagios_notest(testdir, request):
17+
params = ['--nagios', '-q', '--tb=no']
18+
if not request.config.pluginmanager.hasplugin('pytest11.testinfra'):
19+
params.extend(['-p', 'testinfra.plugin'])
20+
result = testdir.runpytest(*params)
1821
assert result.ret == 0
1922
lines = result.stdout.str().splitlines()
2023
assert lines[0].startswith('TESTINFRA OK - 0 passed, 0 failed, 0 skipped')
2124

2225

23-
def test_nagios_ok(testdir):
26+
def test_nagios_ok(testdir, request):
2427
testdir.makepyfile('def test_ok(): pass')
25-
result = testdir.runpytest('--nagios', '-q', '--tb=no')
28+
params = ['--nagios', '-q', '--tb=no']
29+
if not request.config.pluginmanager.hasplugin('pytest11.testinfra'):
30+
params.extend(['-p', 'testinfra.plugin'])
31+
result = testdir.runpytest(*params)
2632
assert result.ret == 0
2733
lines = result.stdout.str().splitlines()
2834
assert lines[0].startswith('TESTINFRA OK - 1 passed, 0 failed, 0 skipped')
2935
assert lines[1][0] == '.'
3036

3137

32-
def test_nagios_fail(testdir):
38+
def test_nagios_fail(testdir, request):
3339
testdir.makepyfile('def test_ok(): pass\ndef test_fail(): assert False')
34-
result = testdir.runpytest('--nagios', '-q', '--tb=no')
40+
params = ['--nagios', '-q', '--tb=no']
41+
if not request.config.pluginmanager.hasplugin('pytest11.testinfra'):
42+
params.extend(['-p', 'testinfra.plugin'])
43+
result = testdir.runpytest(*params)
3544
assert result.ret == 2
3645
lines = result.stdout.str().splitlines()
3746
assert lines[0].startswith(

0 commit comments

Comments
 (0)