-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TST: Fix flaky import test #26953
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
TST: Fix flaky import test #26953
Conversation
I'm not sure what, but the missing depedency test is causing issues. Now we check that things work by running it in a subprocess with site-packages disabled. Closes pandas-dev#26952
Codecov Report
@@ Coverage Diff @@
## master #26953 +/- ##
==========================================
- Coverage 91.87% 91.86% -0.01%
==========================================
Files 180 180
Lines 50746 50746
==========================================
- Hits 46624 46619 -5
- Misses 4122 4127 +5
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #26953 +/- ##
==========================================
- Coverage 91.87% 91.86% -0.01%
==========================================
Files 180 180
Lines 50746 50746
==========================================
- Hits 46624 46619 -5
- Misses 4122 4127 +5
Continue to review full report at Codecov.
|
I think the change here makes sense. But I'm missing something, the test I see failing is related but not the one fixed here:
I can't understand why it's failing, if I understand it correctly, the test says that Not sure how is that possible, the What it comes to my mind is... Since we don't want those attributes to be public attributes of @jreback @jorisvandenbossche I guess you want to have a look here, this is affecting few PRs. |
My guess is that there's a strange interaction between the test / changes in ea06f8d and the existing import builtins
import pandas
import importlib
def mock_import_fail(name, *args, **kwargs):
if name == "numpy":
raise ImportError("cannot import name numpy")
elif name == "pytz":
raise ImportError("cannot import name some_dependency")
elif name == "dateutil":
raise ImportError("cannot import name some_other_dependency")
else:
return original_import(name, *args, **kwargs)
print(len(dir(pandas)))
builtins.__import__ = mock_import_fail
try:
importlib.reload(pandas)
except:
pass
print(len(dir(pandas))) which outputs
So my guess is that if the missing required dep is run before the test_api, we fail. |
Ah, here's a simpler reproducer
I thought I tried that earlier, but apparently I did the wrong one. On my branch that passes. |
I'm going to merge this since this is sometimes affecting other PRs. I'll be around all day to do fixups if needed. |
I'm not sure why, but the missing dependency test is
causing issues. Now we check that things work by running
it in a subprocess with site-packages disabled.
Closes #26952