| 1 |
import py |
| 2 |
|
| 3 |
from pypy.conftest import option |
| 4 |
from pypy.interpreter.error import OperationError |
| 5 |
|
| 6 |
def import_lib_pypy(space, name, skipmsg=None): |
| 7 |
"""Import a top level module ensuring it's sourced from the lib_pypy |
| 8 |
package. |
| 9 |
|
| 10 |
Raises a pytest Skip on ImportError if a skip message was specified. |
| 11 |
""" |
| 12 |
try: |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
failed = ("%s didn't import from lib_pypy. Is a usemodules directive " |
| 17 |
"overshadowing it?" % name) |
| 18 |
importline = ("import %s; assert 'lib_pypy' in %s.__file__, %r; " |
| 19 |
"return %s" % (name, name, failed, name)) |
| 20 |
if option.runappdirect: |
| 21 |
importline = "from lib_pypy " + importline |
| 22 |
return space.appexec([], "(): " + importline) |
| 23 |
except OperationError as e: |
| 24 |
if skipmsg is None or not e.match(space, space.w_ImportError): |
| 25 |
raise |
| 26 |
py.test.skip('%s (%s))' % (skipmsg, str(e))) |