-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reactivate the importing test. #136
Changes from all commits
b5568a7
bf29da8
41183d2
7d39dc2
bdf8cd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,19 @@ | ||
import pytest as pytest_collecting | ||
|
||
from .support import HPyTest | ||
|
||
# this function should probably goes somewhere into hpy.universal and/or and | ||
# hpy package and/or an import hook, or whatever. I do not want to think about | ||
# this now. | ||
def import_module_properly(mod): | ||
raise NotImplementedError("fix me eventually") | ||
|
||
# this was moved from support.py, where it did not belong | ||
## class HPyLoader(ExtensionFileLoader): | ||
## def create_module(self, spec): | ||
## import hpy.universal | ||
## return hpy.universal.load_from_spec(spec) | ||
|
||
|
||
class TestImporting(HPyTest): | ||
|
||
@pytest_collecting.mark.xfail | ||
def test_importing_attributes(self): | ||
import sys | ||
modname = 'mytest' | ||
so_filename = self.compile_module(""" | ||
import pytest | ||
if not self.supports_ordinary_make_module_imports(): | ||
pytest.skip() | ||
mod = self.make_module(""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fear that we are stumbling across each other feet in this PR and #142, sorry for that :(. I strongly believe that See also commit ba33924: I believe that the code written this way is much cleaner and doesn't need all the hacks to sys.path, sys.modules, etc. That said, we surely need a way to properly import modules of course, but it's probably better/easier to leave it clearly separate from the low-level stuff used by tests. So I propose the following:
What do you think about this solution? |
||
@INIT | ||
""", name=modname) | ||
mod = import_module_properly(so_filename, modname) | ||
assert mod in sys.modules | ||
""", name='mytest') | ||
assert mod.__name__ == 'mytest' | ||
assert mod.__package__ == '' | ||
assert mod.__doc__ == 'some test for hpy' | ||
assert mod.__loader__.name == 'mytest' | ||
assert mod.__spec__.loader is mod.__loader__ | ||
assert mod.__spec__.name == 'mytest' | ||
assert mod.__file__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure that copy the loader and spec are the perfect thing to do, but: