4 new commits in pytest:
https://bitbucket.org/hpk42/pytest/commits/2c2048157a12/
Changeset: 2c2048157a12
User: jaraco
Date: 2013-10-10 17:40:31
Summary: Adding test capturing #366 where an error occurs when package
resources are loaded from the test package.
Affected #: 1 file
diff -r abb2eaf10864ef237380150cb61dace37dad2ad7 -r
2c2048157a121db03d3bc06121629b9d98ba4a93 testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -493,3 +493,34 @@
raise e
monkeypatch.setattr(b, "open", open)
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*',
+ ])
https://bitbucket.org/hpk42/pytest/commits/9ce7380eb99c/
Changeset: 9ce7380eb99c
User: jaraco
Date: 2013-10-10 17:56:12
Summary: Register the AssertionRewritingHook loader with pkg_resources;
fixes #366.
Affected #: 1 file
diff -r 2c2048157a121db03d3bc06121629b9d98ba4a93 -r
9ce7380eb99c7d30ca3d4cfdae6782bc0ecfbd15 _pytest/assertion/rewrite.py
--- a/_pytest/assertion/rewrite.py
+++ b/_pytest/assertion/rewrite.py
@@ -41,6 +41,7 @@
def __init__(self):
self.session = None
self.modules = {}
+ self._register_with_pkg_resources()
def set_session(self, session):
self.fnpats = session.config.getini("python_files")
@@ -169,6 +170,23 @@
tp = desc[2]
return tp == imp.PKG_DIRECTORY
+ @classmethod
+ def _register_with_pkg_resources(cls):
+ """
+ Ensure package resources can be loaded from this loader.
+ """
+ try:
+ pkg_resources = __import__('pkg_resources')
+ # access an attribute in case a deferred importer is present
+ pkg_resources.__name__
+ except ImportError:
+ return
+
+ # Since pytest tests are always located in the file system, the
+ # DefaultProvider is appropriate.
+ pkg_resources.register_loader_type(cls, pkg_resources.DefaultProvider)
+
+
def _write_pyc(state, co, source_path, pyc):
# Technically, we don't have to have the same pyc format as
# (C)Python, since these "pycs" should never be seen by builtin
https://bitbucket.org/hpk42/pytest/commits/7bd3084ea722/
Changeset: 7bd3084ea722
User: jaraco
Date: 2013-10-10 23:39:37
Summary: Implement suggestions by HPK
Affected #: 1 file
diff -r 9ce7380eb99c7d30ca3d4cfdae6782bc0ecfbd15 -r
7bd3084ea72250eec2d03952c43d9e4de47753d4 _pytest/assertion/rewrite.py
--- a/_pytest/assertion/rewrite.py
+++ b/_pytest/assertion/rewrite.py
@@ -173,10 +173,11 @@
@classmethod
def _register_with_pkg_resources(cls):
"""
- Ensure package resources can be loaded from this loader.
+ Ensure package resources can be loaded from this loader. May be called
+ multiple times, as the operation is idempotent.
"""
try:
- pkg_resources = __import__('pkg_resources')
+ import pkg_resources
# access an attribute in case a deferred importer is present
pkg_resources.__name__
except ImportError:
https://bitbucket.org/hpk42/pytest/commits/70020cf2651b/
Changeset: 70020cf2651b
User: jaraco
Date: 2013-10-11 00:01:56
Summary: Fix bytes/string mismatch in test on Python 3
Affected #: 1 file
diff -r 7bd3084ea72250eec2d03952c43d9e4de47753d4 -r
70020cf2651ba7bc717586d43dc715c059a71d9a testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -514,6 +514,7 @@
def test_load_resource():
assert isinstance(__loader__, AssertionRewritingHook)
res = pkg_resources.resource_string(__name__,
'resource.txt')
+ res = res.decode('ascii')
assert res == 'Load me please.'
""",
}
Repository URL: https://bitbucket.org/hpk42/pytest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit