# Pruebas de Python

`elide test` no descubre pruebas de Python en 1.6.0; en un directorio solo con Python imprime `No tests found.` y
termina con `0`. En su lugar, lance el ejecutor de pruebas como módulo. El código de salida es el del ejecutor, así que
una prueba fallida hace fallar el comando.

Los ejemplos prueban este módulo:

```python
# 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/` y `tests/` contienen cada uno un `__init__.py` vacío.

## unittest

unittest viene con la biblioteca estándar:

```python
# 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!")
```

```bash
elide python -m unittest discover -s tests -t .
```

```terminaloutput
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
```

## pytest

Instale pytest en un entorno virtual de Python 3.13 ([Paquetes y entornos virtuales](/docs/python-packages)) y ejecútelo
con `VIRTUAL_ENV` definido:

```bash
uv venv --python 3.13 .venv
uv pip install --python .venv/bin/python pytest
```

```python
# tests/test_greeting.py
from greet.cli import greeting


def test_default_name():
    assert greeting("world") == "Hello, world!"
```

```bash
VIRTUAL_ENV=.venv elide python -m pytest -q
```

pytest recopila ambos archivos y termina con:

```terminaloutput
2 passed in 0.03s
```

## En CI

Añada el componente de Python después de instalar Elide (`elide setup python`) y ejecute los mismos comandos; consulte
[Integración continua](/docs/installation/ci-cd#example-workflow).
