/bin/bash: line 1: pytest: command not found

I’m trying to run unit tests and coverage on a python repository.

After setting up a virtual environment and installing dependencies, I keep getting a pytest error.

Error here and config.yml here

version: 2

jobs:
  build:

    docker:
      - image: circleci/python:3.9

    steps:
      - checkout

      - run:
          name: Build Environment
          command: |
            python --version
            python -m venv advanced-algorithms
            source advanced-algorithms/bin/activate
            pip install --upgrade pip
            pip install pytest-cov

      - run:
          name: Perform Unit Tests
          command: |
            export PYTHONPATH=$PWD
            pytest -v
            coverage report -m
            coverage xml
            bash <(curl -s https://codecov.io/bash) -f tests/coverage/coverage.xml

Each run step starts with a fresh shell environment, as if you closed you terminal session and then opened a new one. The filesystem changes will still be there, but the variables you may have set will be gone. So you’ll need to re-source your virtual environment in the unit testing step before running pytest.

2 Likes

@saurabmish, simon is correct. However, is there any particular reason you’re using a virtualenv? Another option is to use the python orb, see here for usage examples with the orb.