Escribe para buscar…

Basic

Code should have a set of automated tests that allow you to design new code and modify existing code while verifying that everything continues to work correctly.

Esta página todavía no se ha traducido — se muestra en su idioma original:English

Introduction

To write a program, you need to test that it works.

Project setup

Create a new project and install the required testing dependencies:

ps
uv init test
cd test
uv add --dev pytest

Assert

Create the file test.py:

python
msg = "Hello World!"
hello = msg[:5]

print(hello)

The old way to test code was to do a “print” and check that the result displayed on screen is what you expected.

shell
uv run test.py
Hello

Instead of doing a print and checking the screen, you can assert the expected result:

Estás leyendo una vista previa.

Inicia sesión para leer el artículo completo. Cualquier cuenta abre 4 artículos gratuitos al mes; el alumnado y el profesorado leen las páginas de su curso sin límite.

Iniciar sesión