Tag: pytest

More Mocking with Pytest

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 […]

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. […]