DEV Community

ShulyAvraham
ShulyAvraham

Posted on

1

Testing for CI

Slides & Examples

Check out testing demo in Python by @szabgab

Fixture

Is the testing environment prior to running the tests

Create a test

Create a new python script with a name starting with test_

vi test_myfunc.py
Enter fullscreen mode Exit fullscreen mode

The python script should include

import mymodule # the mymodule file containing the myfunc function I want to test

def test_myfunc1():
    assert mymodule.myfunc("some input") == "some expected result"

def test_myfunc2():
    assert mymodule.myfunc("other input") == "other expected result"
Enter fullscreen mode Exit fullscreen mode

I can add more test_ functions where each function is a test case.

Run the test

pytest test_myfunc.py
Enter fullscreen mode Exit fullscreen mode

This will run all the test_ functions in test_myfunc.py and show whether the tests passed or failed, based on the expected results, per test function.

Tell pytest to run the tests in random order to make sure that the tests are independent of each other

pytest --rendom-order test_myfunc.py
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free