Adding test capturing #366 where an error occurs when package resources are loaded from the test package.
This commit is contained in:
parent
0335c6d750
commit
00c0d62c9b
|
@ -493,3 +493,34 @@ def test_rewritten():
|
||||||
raise e
|
raise e
|
||||||
monkeypatch.setattr(b, "open", open)
|
monkeypatch.setattr(b, "open", open)
|
||||||
assert not _write_pyc(state, [1], source_path, pycpath)
|
assert not _write_pyc(state, [1], source_path, pycpath)
|
||||||
|
|
||||||
|
def test_resources_provider_for_loader(self, testdir):
|
||||||
|
"""
|
||||||
|
Attempts to load resources from a package should succeed normally,
|
||||||
|
even when the AssertionRewriteHook is used to load the modules.
|
||||||
|
|
||||||
|
See #366 for details.
|
||||||
|
"""
|
||||||
|
pytest.importorskip("pkg_resources")
|
||||||
|
|
||||||
|
testdir.mkpydir('testpkg')
|
||||||
|
contents = {
|
||||||
|
'testpkg/test_pkg': """
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from _pytest.assertion.rewrite import AssertionRewritingHook
|
||||||
|
|
||||||
|
def test_load_resource():
|
||||||
|
assert isinstance(__loader__, AssertionRewritingHook)
|
||||||
|
res = pkg_resources.resource_string(__name__, 'resource.txt')
|
||||||
|
assert res == 'Load me please.'
|
||||||
|
""",
|
||||||
|
}
|
||||||
|
testdir.makepyfile(**contents)
|
||||||
|
testdir.maketxtfile(**{'testpkg/resource': "Load me please."})
|
||||||
|
|
||||||
|
result = testdir.runpytest()
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
'* 1 passed*',
|
||||||
|
])
|
||||||
|
|
Loading…
Reference in New Issue