Skip to content

Commit

Permalink
WIP implement find_spec in terms of find_module
Browse files Browse the repository at this point in the history
Related to pytest-dev#1888
  • Loading branch information
nicoddemus committed Aug 31, 2016
1 parent 82218e4 commit f889cd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions _pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,20 @@ def __init__(self, config):
self._register_with_pkg_resources()
self._must_rewrite = set()

def invalidate_caches(self):
self.modules.clear()

def set_session(self, session):
self.session = session

def find_spec(self, fullname, path, target=None):
loader = self.find_module(fullname, path)
if loader:
import importlib.util
return importlib.util.spec_from_loader(fullname, loader)
else:
return None

def find_module(self, name, path=None):
state = self.config._assertstate
state.trace("find_module called for: %s" % name)
Expand Down Expand Up @@ -210,8 +221,6 @@ def load_module(self, name):
raise
return sys.modules[name]



def is_package(self, name):
try:
fd, fn, desc = imp.find_module(name)
Expand Down
2 changes: 2 additions & 0 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ def consider_env(self):

def consider_module(self, mod):
plugins = getattr(mod, 'pytest_plugins', [])
if isinstance(plugins, str):
plugins = [plugins]
self.rewrite_hook.mark_rewrite(*plugins)
self._import_plugin_specs(plugins)

Expand Down

0 comments on commit f889cd2

Please sign in to comment.