@@ -443,11 +443,7 @@ def test_foo(mocker):
443
443
[pytest]
444
444
mock_traceback_monkeypatch = false
445
445
""" )
446
- if hasattr (testdir , 'runpytest_subprocess' ):
447
- result = testdir .runpytest_subprocess ()
448
- else :
449
- # pytest 2.7.X
450
- result = testdir .runpytest ()
446
+ result = runpytest_subprocess (testdir )
451
447
assert result .ret == 0
452
448
453
449
@@ -483,11 +479,7 @@ def test_foo(mocker):
483
479
stub(1, greet='hello')
484
480
stub.assert_called_once_with(1, greet='hey')
485
481
""" )
486
- if hasattr (testdir , 'runpytest_subprocess' ):
487
- result = testdir .runpytest_subprocess ('--tb=native' )
488
- else :
489
- # pytest 2.7.X
490
- result = testdir .runpytest ('--tb=native' )
482
+ result = runpytest_subprocess (testdir , '--tb=native' )
491
483
assert result .ret == 1
492
484
assert 'During handling of the above exception' not in result .stdout .str ()
493
485
assert 'Differing items:' not in result .stdout .str ()
@@ -508,13 +500,17 @@ def test_foo(mocker):
508
500
[pytest]
509
501
mock_use_standalone_module = true
510
502
""" )
511
- if hasattr (testdir , 'runpytest_subprocess' ):
512
- result = testdir .runpytest_subprocess ()
513
- else :
514
- # pytest 2.7.X
515
- result = testdir .runpytest ()
503
+ result = runpytest_subprocess (testdir )
516
504
assert result .ret == 3
517
505
result .stderr .fnmatch_lines ([
518
506
"*No module named 'mock'*" ,
519
507
])
520
508
509
+
510
+ def runpytest_subprocess (testdir , * args ):
511
+ """Testdir.runpytest_subprocess only available in pytest-2.8+"""
512
+ if hasattr (testdir , 'runpytest_subprocess' ):
513
+ return testdir .runpytest_subprocess (* args )
514
+ else :
515
+ # pytest 2.7.X
516
+ return testdir .runpytest (* args )
0 commit comments