Verify that CI integration runs tests automatically on code push
Preconditions (3)
✅ Expected Result: The CI service automatically runs the pytest tests on the pushed commit and reports all tests passing without manual intervention
Jump into concepts and practice - no test required
import pytest # Sample function to test def add(a, b): return a + b # Test case to verify add function def test_add_positive_numbers(): assert add(2, 3) == 5 def test_add_negative_numbers(): assert add(-1, -1) == -2 def test_add_zero(): assert add(0, 0) == 0 # To run these tests, push this code to your Git repo and observe CI running pytest automatically if __name__ == "__main__": pytest.main(["-v"])
This script defines a simple add function and three pytest test functions to check it with positive numbers, negative numbers, and zero.
Each test uses assert to verify the expected output.
When this code is pushed to a Git repository configured with CI (like GitHub Actions), the CI system will automatically run pytest and report the results.
This automation ensures continuous quality by running tests on every code change without manual effort.
Now add data-driven testing with 3 different input pairs for the add function
pytest.--run-all, --ci-mode, and --skip are not standard pytest commands.============================= test session starts =============================
collected 3 items
test_sample.py ..F [100%]
================================== FAILURES ===================================
____________________________ test_divide_by_zero _____________________________
def test_divide_by_zero():
> assert 1 / 0
E ZeroDivisionError: division by zero
ZeroDivisionError in test_divide_by_zero.test_.black --check. Which approach best integrates this to maintain continuous quality?black --check first; if it fails, stop pipeline to fix formatting before running tests.black --check first; if it fails, stop the pipeline; else run pytest tests -> Option A