Merge pull request #2222 from RonnyPfannschmidt/features
merge master into features
This commit is contained in:
@@ -59,6 +59,23 @@ class TestImportHookInstallation:
|
||||
assert 0
|
||||
result.stdout.fnmatch_lines([expected])
|
||||
|
||||
def test_rewrite_assertions_pytester_plugin(self, testdir):
|
||||
"""
|
||||
Assertions in the pytester plugin must also benefit from assertion
|
||||
rewriting (#1920).
|
||||
"""
|
||||
testdir.makepyfile("""
|
||||
pytest_plugins = ['pytester']
|
||||
def test_dummy_failure(testdir): # how meta!
|
||||
testdir.makepyfile('def test(): assert 0')
|
||||
r = testdir.inline_run()
|
||||
r.assertoutcome(passed=1)
|
||||
""")
|
||||
result = testdir.runpytest_subprocess()
|
||||
result.stdout.fnmatch_lines([
|
||||
'*assert 1 == 0*',
|
||||
])
|
||||
|
||||
@pytest.mark.parametrize('mode', ['plain', 'rewrite'])
|
||||
def test_pytest_plugins_rewrite(self, testdir, mode):
|
||||
contents = {
|
||||
|
||||
@@ -682,7 +682,7 @@ def test_rewritten():
|
||||
hook.mark_rewrite('test_remember_rewritten_modules')
|
||||
assert warnings == []
|
||||
|
||||
def test_rewrite_warning_using_pytest_plugins(self, testdir, monkeypatch):
|
||||
def test_rewrite_warning_using_pytest_plugins(self, testdir):
|
||||
testdir.makepyfile(**{
|
||||
'conftest.py': "pytest_plugins = ['core', 'gui', 'sci']",
|
||||
'core.py': "",
|
||||
@@ -695,6 +695,22 @@ def test_rewritten():
|
||||
result.stdout.fnmatch_lines(['*= 1 passed in *=*'])
|
||||
assert 'pytest-warning summary' not in result.stdout.str()
|
||||
|
||||
def test_rewrite_warning_using_pytest_plugins_env_var(self, testdir, monkeypatch):
|
||||
monkeypatch.setenv('PYTEST_PLUGINS', 'plugin')
|
||||
testdir.makepyfile(**{
|
||||
'plugin.py': "",
|
||||
'test_rewrite_warning_using_pytest_plugins_env_var.py': """
|
||||
import plugin
|
||||
pytest_plugins = ['plugin']
|
||||
def test():
|
||||
pass
|
||||
""",
|
||||
})
|
||||
testdir.chdir()
|
||||
result = testdir.runpytest_subprocess()
|
||||
result.stdout.fnmatch_lines(['*= 1 passed in *=*'])
|
||||
assert 'pytest-warning summary' not in result.stdout.str()
|
||||
|
||||
|
||||
class TestAssertionRewriteHookDetails(object):
|
||||
def test_loader_is_package_false_for_module(self, testdir):
|
||||
|
||||
@@ -587,6 +587,21 @@ def test_load_initial_conftest_last_ordering(testdir):
|
||||
assert [x.function.__module__ for x in l] == expected
|
||||
|
||||
|
||||
def test_get_plugin_specs_as_list():
|
||||
from _pytest.config import _get_plugin_specs_as_list
|
||||
with pytest.raises(pytest.UsageError):
|
||||
_get_plugin_specs_as_list(set(['foo']))
|
||||
with pytest.raises(pytest.UsageError):
|
||||
_get_plugin_specs_as_list(dict())
|
||||
|
||||
assert _get_plugin_specs_as_list(None) == []
|
||||
assert _get_plugin_specs_as_list('') == []
|
||||
assert _get_plugin_specs_as_list('foo') == ['foo']
|
||||
assert _get_plugin_specs_as_list('foo,bar') == ['foo', 'bar']
|
||||
assert _get_plugin_specs_as_list(['foo', 'bar']) == ['foo', 'bar']
|
||||
assert _get_plugin_specs_as_list(('foo', 'bar')) == ['foo', 'bar']
|
||||
|
||||
|
||||
class TestWarning:
|
||||
def test_warn_config(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
|
||||
@@ -7,16 +7,12 @@ from _pytest.monkeypatch import MonkeyPatch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mp(request):
|
||||
def mp():
|
||||
cwd = os.getcwd()
|
||||
sys_path = list(sys.path)
|
||||
|
||||
def cleanup():
|
||||
sys.path[:] = sys_path
|
||||
os.chdir(cwd)
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return MonkeyPatch()
|
||||
yield MonkeyPatch()
|
||||
sys.path[:] = sys_path
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
def test_setattr():
|
||||
@@ -329,5 +325,3 @@ def test_issue1338_name_resolving():
|
||||
monkeypatch.delattr('requests.sessions.Session.request')
|
||||
finally:
|
||||
monkeypatch.undo()
|
||||
|
||||
|
||||
|
||||
@@ -124,3 +124,10 @@ def test_inline_run_clean_modules(testdir):
|
||||
test_mod.write("def test_foo(): assert False")
|
||||
result2 = testdir.inline_run(str(test_mod))
|
||||
assert result2.ret == EXIT_TESTSFAILED
|
||||
|
||||
def test_assert_outcomes_after_pytest_erro(testdir):
|
||||
testdir.makepyfile("def test_foo(): assert True")
|
||||
|
||||
result = testdir.runpytest('--unexpected-argument')
|
||||
with pytest.raises(ValueError, message="Pytest terminal report not found"):
|
||||
result.assert_outcomes(passed=0)
|
||||
|
||||
Reference in New Issue
Block a user