diff options
author | Bruno Oliveira <nicoddemus@gmail.com> | 2016-08-30 22:15:53 -0300 |
---|---|---|
committer | Bruno Oliveira <nicoddemus@gmail.com> | 2016-08-30 22:53:50 -0300 |
commit | c8a366e5510d1317066ef471cb1a056f902e8a5a (patch) | |
tree | 9bc579a37997446d0c4761d56fdd58baa3f3cc86 /testing | |
parent | 82218e4ee1d9b376021dab69bce9f9b01ff61d84 (diff) | |
download | pytest-c8a366e5510d1317066ef471cb1a056f902e8a5a.tar.gz |
Fix issue where pytest_plugins as string was marking wrong modules for rewrite
Fix #1888
Diffstat (limited to 'testing')
-rw-r--r-- | testing/test_assertion.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/testing/test_assertion.py b/testing/test_assertion.py index a3a29a76c..d49815181 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -84,6 +84,29 @@ class TestImportHookInstallation: assert 0 result.stdout.fnmatch_lines([expected]) + @pytest.mark.parametrize('mode', ['str', 'list']) + def test_pytest_plugins_rewrite_module_names(self, testdir, mode): + """Test that pluginmanager correct marks pytest_plugins variables + for assertion rewriting if they are defined as plain strings or + list of strings (#1888). + """ + plugins = '"ham"' if mode == 'str' else '["ham"]' + contents = { + 'conftest.py': """ + pytest_plugins = {plugins} + """.format(plugins=plugins), + 'ham.py': """ + import pytest + """, + 'test_foo.py': """ + def test_foo(pytestconfig): + assert 'ham' in pytestconfig.pluginmanager.rewrite_hook._must_rewrite + """, + } + testdir.makepyfile(**contents) + result = testdir.runpytest_subprocess('--assert=rewrite') + assert result.ret == 0 + @pytest.mark.parametrize('mode', ['plain', 'rewrite']) def test_installed_plugin_rewrite(self, testdir, mode): # Make sure the hook is installed early enough so that plugins @@ -196,6 +219,12 @@ class TestImportHookInstallation: '>*assert l.pop() == 3*', 'E*AssertionError']) + def test_register_assert_rewrite_checks_types(self): + with pytest.raises(TypeError): + pytest.register_assert_rewrite(['pytest_tests_internal_non_existing']) + pytest.register_assert_rewrite('pytest_tests_internal_non_existing', + 'pytest_tests_internal_non_existing2') + class TestBinReprIntegration: |