-
Notifications
You must be signed in to change notification settings - Fork 221
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
Fix getting module with --import-mode=importlib #381
Conversation
I think the approach is sound, and indeed it was the best way I could find to do the same thing in The failures are related to py27: you will need to update the custom |
Oh, I didn't realize pytest-bdd still supported Python 2... I ended up just moving the imports, as this scenario only happens with |
You are right, good point! Seems now only linters have failed. 👍 |
Fixed!
|
Codecov Report
@@ Coverage Diff @@
## master #381 +/- ##
==========================================
- Coverage 95.51% 94.89% -0.62%
==========================================
Files 48 48
Lines 1671 1686 +15
Branches 167 170 +3
==========================================
+ Hits 1596 1600 +4
- Misses 43 53 +10
- Partials 32 33 +1
Continue to review full report at Codecov.
|
Thanks for the patch, @The-Compiler. Sorry for the late response. |
I'll take a look - I wasn't sure how much work that'd be, but I guess with the migration to pytester/testdir tests and |
I tried to add a test to def test_importlib(testdir):
"""Test scenario function with importlib import mode."""
testdir.makefile(
".feature",
simple="""
Feature: Simple feature
Scenario: Simple scenario
Given I have a bar
""",
)
testdir.makepyfile(
"""
from pytest_bdd import scenario, given
@scenario("simple.feature", "Simple scenario")
def test_simple():
pass
@given("I have a bar")
def bar():
return "bar"
"""
)
result = testdir.runpytest_subprocess('--import-mode=importlib')
result.assert_outcomes(passed=1) but it fails with this inside the subprocess:
Note the wrong path to @nicoddemus do you have an idea what's going on there? |
Sorry, no. 😞 One difference is that |
I'm trying to get this to work (starting from the test you posted) on another branch too: https://github.com/pytest-dev/pytest-bdd/tree/work-with-importlib. I fixed the Unfortunately, now there is another issue where the fixture
This happens only when running the test with |
It seems that the module object where we set the fixture (done by I added some print statements so that I can confirm this.
The This is instead the execution with
The fixture is set on a different module object, and the fixture lookup will fail. |
So it seems that indeed |
I may have found a way, replacing (in
with
|
Fixed in #384. Thanks for your effort and for bringing this up. |
With the pytest 6 RC, a new
--import-mode=importlib
was added, which usesimportlib
rather thansys.path
hacks to import test modules. I'd really like to use it, and in future pytest releases that'll become the default.Unfortunately, it fails with pytest-bdd:
because
module
here isNone
(relevant code):This fix seems to work, and is inspired from how pytest imports modules in this case. I'm not sure if it's the right solution though, there might be some easier way towards the same goal?
cc @nicoddemus