Replies: 1 comment
-
actually I think I figured this out by putting conftest.py in the project root directory and putting this function in it @pytest.fixture(autouse=True)
def inject_doctest_namespace(doctest_namespace, myt_api):
doctest_namespace["api"] = my_api |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I am currently working on a project that makes extensive use of pytest for testing. Within my project, I have numerous doctests embedded within the docstrings of pretty much every methods. However, all of these doctests require a certain context to be established beforehand, namely, an active instance of our custom API.
Currently, I have been including a context manager within every single doctest example to ensure the necessary API instance is available. Here’s a simplified example to illustrate the setup:
However, this makes the doctests quite verbose, harder to maintain, and somewhat obscures the actual examples I'm trying to provide. I am looking for a way to establish this context for all doctests within a module or class globally, so that I don't have to repeat the context manager setup in every single doctest.
Is there an existing solution or best practice to manage the context for pytest doctests more efficiently? Or perhaps a way to establish a module-level or class-level setup that applies to all doctests within that scope?
Beta Was this translation helpful? Give feedback.
All reactions