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
In software development, it is common to face situations where unit tests cannot be executed due to changes or ongoing development. In these cases, commenting out test code is not the best practice. Fortunately, Python and unittest
offer decorators that allow us to temporarily skip tests without compromising workflow and project integrity. Here we will learn how to use decorators like @skip
, @skipIf
and @expectedFailure
to handle these cases efficiently.
The @skip
decorator is used when we know that a test should not be executed temporarily. This is useful if we are working on a feature that is not yet complete and, therefore, the tests do not make sense. By applying @skip
, we can avoid executing the test and still have visibility that it is pending fixes.
@unittest.skip("Work in progress, will be re-enabled.")def test_skip_example(self):self.assertEqual("hello", "bye").
The @skipIf
decorator is useful when we want to skip a test under a specific condition. This is common when our tests depend on the environment, such as different servers or specific configurations.
server = "server_b"@unittest.skipIf(server == "server_a", "Skipped because we are not on the correct server.")def test_skipif_example(self):self.assertEqual(1000, 100)
This decorator is used when we know a test will fail due to a change in business logic or a known bug, but we want to keep the test visible in the test report.
@unittest.expectedFailuredef test_expected_failure_example(self):self.assertEqual(100, 150).
The @skipUnless
decorator is valuable when we want to run a test only if a condition is met. A classic example is to validate if an external service, such as an API, is available before running the test.
@unittest.skipUnless(api_available(), "API not available.")def test_skipunless_example(self):self.assertEqual(get_currency_rate("USD"), 1.0)
Using decorators like @skip
, @skipIf
, @expectedFailure
and @skipUnless
in a development team ensures that tests do not interfere with the workflow, while maintaining visibility of pending tests. It is essential in continuous integration (CI) environments, where you want tests to not block development, but not ignore them completely.
Contributions 6
Questions 1
Want to see more contributions, questions and answers from the community?