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
This is an awesome library - thanks for creating and maintaining it!
If I have a markdown doc that has 2 code snippets, is there any way to mark that the second one relies on the first one and therefore, in order to test the second example you need to take the code from the first example too?
E.g. test.md
You can import environment variables like this:
importoss.environ.get("MY_ENV_VAR")
And you can also specify a default value:
s.environ.get("MY_ENV_VAR", "default")
The text was updated successfully, but these errors were encountered:
Just coming back to this, I found there is a way to do this within the current setup. If you add depends_on=<> as a tag to one example, id=<> to another example and then have the following in your run code, it works. It's a little hacky and would be nicer if it were packaged better, but does the job 😃
@pytest.mark.parametrize("example", find_examples("docs/product/"), ids=str)deftest_docstrings(example: CodeExample, eval_example: EvalExample):
# For example, if you have depends_on=example1, then we'll look for an example with# id=example1 and load that code in before the current example.dependent_examples= [
_get_example_by_id(tag.split("depends_on=")[1])
fortaginexample.prefix_tags()
if"depends_on="intag
]
example.source="\n".join(
[dependent_example.sourcefordependent_exampleindependent_examples]
+ [example.source]
)
eval_example.run(example)
def_get_example_by_id(id: str) ->CodeExample:
forexampleinfind_examples("docs/product/"):
iff"id={id}"inexample.prefix_tags():
returnexampleraiseValueError(f"Example with id {id} not found")
This is an awesome library - thanks for creating and maintaining it!
If I have a markdown doc that has 2 code snippets, is there any way to mark that the second one relies on the first one and therefore, in order to test the second example you need to take the code from the first example too?
E.g. test.md
You can import environment variables like this:
And you can also specify a default value:
The text was updated successfully, but these errors were encountered: