You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my package I'm checking for an extra dependency with a code like this:
try:
importtyperexceptImportError:
print("error: typer not installed", file=sys.stderr)
sys.exit(1)
Can't find a way to test this. Patching "builtins.__import__" with a temporary mock_import works only if no previous import typer calls were made.
So if invoking pytest test_dynamic_import.py, it's working, but bare pytest analyzes and performs imports in other testfiles that import the main package where the dynamic import code is executed, so typer is already imported when the test function with the patch code in the test_dynamic_import.py file is invoked.
I believe there should be a more straightforward method to test for dynamic imports. Please, advise.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In my package I'm checking for an extra dependency with a code like this:
Can't find a way to test this. Patching
"builtins.__import__"
with a temporarymock_import
works only if no previousimport typer
calls were made.So if invoking
pytest test_dynamic_import.py
, it's working, but barepytest
analyzes and performs imports in other testfiles that import the main package where the dynamic import code is executed, so typer is already imported when the test function with the patch code in thetest_dynamic_import.py
file is invoked.I believe there should be a more straightforward method to test for dynamic imports. Please, advise.
Beta Was this translation helpful? Give feedback.
All reactions