Search code examples
pythonflaskpytestconfigcircleci

Circleci does not work with my config.yml file when trying to run 'pytest --html=pytest_report.html', producing the error 'no such option: --html'


What I tried: placing 'pip install --user -r requirements.txt' in the second run command placing 'pip install pytest' in the second run command along with 'pip install pytest-html'

both followed by, pytest --html=pytest_report.html

I am new to CircleCI and using pytest as well Here is the steps portion of the config.yml file

version: 2.1
jobs:
  run_tests:
    docker:
      - image: circleci/python:3.9.1

    steps:
      - checkout
      - run:
        name: Install Python Dependencies
        command:
          echo 'export PATH=~$PATH:~/.local/bin' >> $BASH_ENV && source $BASH_ENV
          pip install --user -r requirements.txt
      - run:
        name: Run Unit Tests
        command:
          pip install --user -r requirements.txt
          pytest --html=pytest_report.html
      - store_test_results:
          path: test-reports
      - store_artifacts:
          path: test-reports
workflows:
  build_test:
    jobs:
      - run_tests

Solution

  • --html is not one of the builtin options for pytest -- it likely comes from a plugin

    I believe you're looking for pytest-html -- make sure that's listed in your requirements

    it's also possible / likely that the pip install --user is installing another copy of pytest into the image which'll only be available at ~/.local/bin/pytest instead of whatever pytest comes with the circle ci image


    disclaimer, I'm one of the pytest core devs