diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-10-10 11:56:12 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-10-10 11:56:12 -0400 |
commit | a4c17dfb19b1c1bfe1e380da72b1364f31cfd7a9 (patch) | |
tree | c7ae391158fa9a1ee7eca14555dc57f7d0f0f415 /_pytest | |
parent | 00c0d62c9b137a343a157bfc2afadd78ac9af981 (diff) | |
download | pytest-a4c17dfb19b1c1bfe1e380da72b1364f31cfd7a9.tar.gz |
Register the AssertionRewritingHook loader with pkg_resources; fixes #366.
Diffstat (limited to '_pytest')
-rw-r--r-- | _pytest/assertion/rewrite.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index f79698ae4..1f05fc51c 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -41,6 +41,7 @@ class AssertionRewritingHook(object): 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 @@ class AssertionRewritingHook(object): 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 |