pySearch: Adding a Test Framework

Ever since the regression that occurred in pySearch’s initially merged PR implementing tests have been my top priority. When I was looking at a bug in the pipenv repository I noticed they used pytest to test their code and I thought it would be a good idea to use pytest for pySearch.

I started off by creating a simple creating a tests folder. Inside this folder I created a requirements.txt to centralize all dependency installs for the tests in the future.

As pytest is a non-standard Python library it needs to be installed by pip. Next I created a basic test which verifies the functionality of the buildLink function.

Initially the test tried to import the Search object from the pySearch.py script but the main function was interfering with pytest so I had to abstract it out.

Then I ran into an issue where Python couldn’t find the module in the path because Python did not identify it as part of a package. To fix that I added an empty __init__.py to both the test directory and the root directory.

Now this is what the code structure looked like after the refactor.

Let’s run the test to see if it works by running pytest

Passed is good but let’s make sure that everything is set up correctly. Let’s see what happens if we change the control output to a different value.

Yup it looks like everything is running as it should!