Testing external code
The main objective of testing is to be able to check code that's out of the boundaries of the test files. We can import code easily in the tests, and then verify whether it is working as expected. Let's see how to do it.
Getting ready
We will use the pytest
module. We should install the module, adding it to our requirements.txt
file as follows:
$ echo "pytest==5.4.1" >> requirements.txt
$ pip install -r requirements.txt
We will use the test files tests/test_external.py
and code/external.py
. You can download them from the GitHub repository at https://github.com/PacktPublishing/Python-Automation-Cookbook-Second-Edition/tree/master/Chapter12, under the subdirectories tests
and code
.
The tree should look like this:
├── code
│  ├── __init__.py
│  └── external.py
├── conftest.py
└─&...