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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up