Skip to content

Python tests

Run Python tests on Elide with unittest from the standard library or pytest from a virtual environment; elide test does not discover Python tests in 1.6.0.

On this page

elide test does not discover Python tests in 1.6.0; in a Python-only directory it prints No tests found. and exits 0. Run the test runner as a module instead. The exit code is the runner’s, so a failing test fails the command.

The examples test this module:

# greet/cli.py
import sys


def greeting(name: str) -> str:
    return f"Hello, {name}!"


def main() -> int:
    print(greeting(sys.argv[1] if len(sys.argv) > 1 else "world"))
    return 0

greet/ and tests/ each contain an empty __init__.py.

unittest

unittest ships with the standard library:

# tests/test_cli.py
import unittest

from greet.cli import greeting


class GreetingTest(unittest.TestCase):
    def test_names_the_caller(self):
        self.assertEqual(greeting("Elide"), "Hello, Elide!")
elide python -m unittest discover -s tests -t .
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

pytest

Install pytest into a Python 3.13 virtual environment (Packages and virtual environments), then run it with VIRTUAL_ENV set:

uv venv --python 3.13 .venv
uv pip install --python .venv/bin/python pytest
# tests/test_greeting.py
from greet.cli import greeting


def test_default_name():
    assert greeting("world") == "Hello, world!"
VIRTUAL_ENV=.venv elide python -m pytest -q

pytest collects both files and ends with:

2 passed in 0.03s

In CI

Add the Python component after installing Elide (elide setup python), then run the same commands; see Continuous Integration.

Was this page helpful?