AI Hints
Home›CI/CD with GitHub Actions Tutorial›Pipelines and Our Project
CI/CD with GitHub Actions · Lesson 6 of 138

Running Tests by Hand

What CI will do for us.

⏱ 2 min read▶ Video at 5:48🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Before automating anything, always run it by hand first. If you can't run your tests on your own machine, a CI server won't be able to either. So let's run the tests, and the linter, exactly as our pipeline will.

Running Tests by Hand
From the video: Running Tests by Hand
  • Run it by hand first
  • Same as the pipeline
  • Tests and linter

pytest and flake8

Pytest dash Q runs every test quietly. Three dots, three passed. Then flake8 checks the code style. It printed nothing, which means no problems. Finally, echo dollar question mark shows the exit code of the last command. Zero means success. That number is how CI knows whether a step passed.

Terminal
pytest -q
...                                                                                [100%]
3 passed in 0.01s
flake8
echo $?
0

A failing test

Now let's break something on purpose. Sed changes the tax from point two to point three. Pytest finds the problem straight away. It shows which test failed, what it expected, and what it got. And the exit code is one, not zero. A pipeline would stop right here, and mark the change as failed.

Terminal
sed -i 's/tax=0.2/tax=0.3/' app.py
pytest -q
F..                                                                                [100%]
======================================== FAILURES ========================================
__________________________________ test_total_adds_tax ___________________________________

    def test_total_adds_tax():
>       assert total([10, 20]) == 36.0
E       assert 39.0 == 36.0
E        +  where 39.0 = total([10, 20])

test_app.py:6: AssertionError
================================ short test summary info =================================
FAILED test_app.py::test_total_adds_tax - assert 39.0 == 36.0
1 failed, 2 passed in 0.02s
echo $?
1

Summary

Tests return exit code zero when they pass, and something else when they fail. That's exactly how a pipeline decides. Next, a quick git refresher.

Key takeaways
  • pytest -q
  • flake8
  • Exit code 0 = pass
Next up: Git in Two Minutes — commits and history