In my Basic Mocking with Pytest post I showed simple cases. Now let’s do more mocking. First I’ll create the environment for my code: $ mkdir more-mocking$ cd more-mocking$ python3 -m venv venv$ . venv/bin/activate(venv)$ pip install -U pip wheel…Successfully installed pip-24.0 wheel-0.43.0(venv)$ pip install pynetbox pytest…Successfully installed certifi-2024.2.2 charset-normalizer-3.3.2 idna-3.7 iniconfig-2.0.0 packaging-23.2 pluggy-1.5.0 pynetbox-7.3.3 […]
Tag: pytest
Parametrizing Test Functions with Pytest
I will first create a class that is used for representing the Zabbix protocol flags (zabbix_flags.py): Subclassing enum.IntFlag is very suitable for this purpose, and enum.auto() can be used to represent the flag values. I have four test functions to check that the flag values work as expected (test_zabbix_flags.py): Let’s create a virtual environment and […]
Basic Mocking with Pytest
Since I always seem to search for these examples over and over again, here it is, basic mocking with pytest. My example code is this (testmodule.py): It can be run: $ python3 testmodule.py In testfunc, sleeping $ Not surprisingly, running it takes about five seconds. The time.sleep() call simulates some long-running operation in the code. […]