DEV Community


Posted on


Testing for CI

Slides & Examples

Check out testing demo in Python by @szabgab


Is the testing environment prior to running the tests

Create a test

Create a new python script with a name starting with test_

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

Enter fullscreen mode Exit fullscreen mode

This will run all the test_ functions in 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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.