![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Pytest plugin for testing Python code examples in docstrings and markdown files.
pytest-examples
can:
ruff
and black
It can also update code examples in place to format them and insert or update print statements.
pip install -U pytest-examples
Here's an example basic usage - lint then run examples in the foo_dir
directory and the bar_file.py
file.
import pytest
from pytest_examples import find_examples, CodeExample, EvalExample
@pytest.mark.parametrize('example', find_examples('foo_dir', 'bar_file.py'), ids=str)
def test_docstrings(example: CodeExample, eval_example: EvalExample):
eval_example.lint(example)
eval_example.run(example)
pytest-examples
can also check print statements are inserted correctly.
There's the expected format of prints statemints in docstrings:
def add_two_things(a, b):
"""
```py
from my_lib import add_two_things
print(add_two_things(1, 2))
#> 3
```
"""
return a + b
And here's an example of a markdown file, again documenting add_two_things
:
# How `add_two_things` works
```py
from my_lib import add_two_things
print(add_two_things(1, 2))
#> 3
```
pytest-examples
can then run the code and check the print statements are correct:
import pytest
from pytest_examples import find_examples, CodeExample, EvalExample
@pytest.mark.parametrize('example', find_examples('foo_dir'), ids=str)
def test_docstrings(example: CodeExample, eval_example: EvalExample):
eval_example.run_print_check(example)
As well as checking linting and print statements, are correct, we can also update files.
This requires the --update-examples
flags AND use of the format()
and run_print_update()
methods.
Here's a full example of a unit test that checks code when called normally, but can update it when the flag is set:
import pytest
from pytest_examples import find_examples, CodeExample, EvalExample
@pytest.mark.parametrize('example', find_examples('README.md'), ids=str)
def test_readme(example: CodeExample, eval_example: EvalExample):
if eval_example.update_examples:
eval_example.format(example)
eval_example.run_print_update(example)
else:
eval_example.lint(example)
eval_example.run_print_check(example)
FAQs
Pytest plugin for testing examples in docstrings and markdown files.
We found that pytest-examples demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.