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
When running doctest, a (copy of) the module’s globals will be used, so even without importing a package inside a docstring, the test will pass (if it is imported at the top level of the module). See the example at the end.
However, it implies that when a user copy-paste a docstring to run the example, it could fail due to missing imports, even if the doctest passes in the CI.
In doctest module, there is a notion called execution context, and we can pass globs=your_dict to testmod() in order to change it.
However, I could not find a way to use such mechanism when launching doctest through pytest.
Question: Is it possible to use custom globals when running pytest --doctest-module?
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
Uh oh!
There was an error while loading. Please reload this page.
-
When running doctest, a (copy of) the module’s globals will be used, so even without importing a package inside a docstring, the test will pass (if it is imported at the top level of the module). See the example at the end.
However, it implies that when a user copy-paste a docstring to run the example, it could fail due to missing imports, even if the doctest passes in the CI.
In doctest module, there is a notion called
execution context
, and we can passglobs=your_dict
totestmod()
in order to change it.However, I could not find a way to use such mechanism when launching doctest through
pytest
.Question: Is it possible to use custom globals when running
pytest --doctest-module
?Example
dummy_test.py
Beta Was this translation helpful? Give feedback.
All reactions