Setup pytest#

We also want testing for our Python code, so let’s get pytest installed.

Install and Config#

To start, we’ll add pytest to the dependencies in pyproject.toml. Really, they should go in dev dependencies, but this project really just a tutorial. Let’s go ahead and add all the dependencies we’ll need for the next few steps:

dependencies = [

After adding, we do:

$ pip install -e .

We’ll also start the process of centralizing our pytest options. Instead of pytest.ini, we’ll use [tool.pytest.ini_options] in pyproject.toml. As an example, add this to pyproject.toml to configure strict marker usage in pytest:

addopts = "--strict-markers"

First Python Code and Test#

As before, we’ll put a little tracer in our Python code and write a simple test.

In src/pyodide_components/


Then, in tests/

from pyodide_components import PYODIDE_COMPONENTS

def test_hello():
    assert PYODIDE_COMPONENTS == "Hello"

Running pytest shows that the test passes.