• Home
  • Public Speaking
  • Travel

Running PyTest Environment Independently

Let's remember the famous saying: "It is running on my machine." Sometimes, we implement test code and everything runs perfectly. But when we move to another machine or maybe on Pipelines, we are missing lots of libraries and dependencies. Here is the way to manage it.

1. Make paths relative

Paths can make trouble since clones can be placed in different folders. Two most possible things we may use are locating a file relatively to the root path and relatively to the working directory.

path=os.path.join(os.path.expanduser('~'), 'somefile') path=os.path.join(os.path.dirname(__file__), 'somefile')

2. Manage Dependencies

To install dependencies automatically, we can use pipenv, which ensures a stable environment with accurate versions. In the project directory, first install pipenv:

pip install --user pipenv

Then we install the dependencies with pipenv:

pipenv install requests

A pipfile will be created in the project afterwards:
Then the only thing we have to do is to run:

pipenv run pytest