Fundamentos del Testing en Python
驴Qu茅 son las Pruebas Unitarias y por qu茅 es importante?
驴Qu茅 es el Testing en Software?
Instalaci贸n y Configuraci贸n del Entorno de Pruebas
Conceptos B谩sicos de Unittest
C贸mo Crear Pruebas Unitarias con UnitTest en Python
C贸mo usar el m茅todo setup en tests de Python
Uso de tearDown para limpieza de Pruebas Unitarias en Python
C贸mo validar excepciones y estructuras de datos con Unittest en Python
Control de pruebas unitarias con unittest.skip en Python
Organizaci贸n y Gesti贸n de Pruebas
C贸mo organizar y ejecutar pruebas en Python con UnitTest
Mejores pr谩cticas para organizar y nombrar pruebas en Python
T茅cnicas Avanzadas en Pruebas Unitarias
Mocking de APIs externas en Python con unittest
Uso de Side Effects en Mocking con Python
Uso de Patching para Modificar Comportamientos en Python
Exploraci贸n de Herramientas y M茅todos Complementarios
C贸mo parametrizar pruebas en Python con SubTest
Documentaci贸n de pruebas unitarias con Doctest en Python
C贸mo generar datos de prueba din谩micos con Faker en Python
Mejora y Automatizaci贸n de Pruebas
驴C贸mo asegurar la cobertura de pruebas con Coverage en Python
Automatizaci贸n de Pruebas Unitarias en Python con GitHub Actions
Pruebas Unitarias con PyTest en Python
C贸mo crear pruebas unitarias con inteligencia artificial en Python
You don't have access to this class
Keep learning! Join and start boosting your career
Python offers a wide variety of tools, and one of the most useful for automated testing is PyTest. PyTest greatly enhances the developer experience by allowing you to write and run tests more efficiently. In this guide we will see how to install PyTest, create parameterized tests and run a basic example.
:pip install pytest
requirements.txt
file with:pip freeze | grep pytest > requirements.txt
test_pytest.py.
:import pytest
:def test_sum():a = 4b = 4 assert a + b == 8
:pytest test_pytest.py
PyTest does not require the creation of classes to group tests, which simplifies the code. In this case, tests are grouped by file.
prueba:@pytest.mark.parametrize("amount, expected", [(100, 5000), (200, 5500), (300, 6000) ])def test_balance(amount, expected): assert calculate_balance(amount) == expected
amount
and expected
.:pytest -v
-v
option, PyTest details which tests were run and their results.If a test fails, PyTest will tell you exactly which values did not match. For example, if one of the expected values is incorrect:
def test_balance(): assert calculate_balance(100) == 5400 # This value is incorrect.
When you run the test again, PyTest will show you the difference between the expected value and the actual value.
Refactor all the tests in your project to use PyTest, applying what we have seen about parameterization and the use of simpler asserts.
Contributions 6
Questions 0
Want to see more contributions, questions and answers from the community?