First time using Bitbucket Pipeline. PyTest file or directory not found: tests/*

This is my first time using Bitbucket Pipeline to build a python program. The code I have is this:

image: python:3.8.11

pipelines:
  default:
    - step:
        name: Install dependencies
        script:
          - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - step:
        name: PyTest
        script:
          - pip install pytest
          - pytest -v tests/* --junitxml=test-reports\report.xml
    - step:
        name: Unit test
        script:
          - python -m unittest discover tests-reports/
    - step:
        name: Django test
        script:
          - pip install django
          - python manage.py test
    - step:
        name: Lint code
        script:
          # Enforce style consistency across Python projects https://flake8.pycqa.org/en/latest/manpage.html
          - pip install flake8
          - flake8 . --extend-exclude=dist,build --show-source --statistics

The first step "Install dependencies" passes. But the second step "PyTest" fails. Here is the error message:

+ pytest -v tests/* --junitxml=test-reports\report.xml
============================= test session starts ==============================
platform linux -- Python 3.8.11, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /opt/atlassian/pipelines/agent/build
collecting ... collected 0 items
- generated xml file: /opt/atlassian/pipelines/agent/build/test-reportsreport.xml -
============================ no tests ran in 0.00s =============================
ERROR: file or directory not found: tests/*

I am not sure what is going on with pipeline and deployment as I am new to the process. Can anyone let me know how to resolve this?

1 answer

  • answered 2021-07-27 19:02 j_b

    From the error, it appears that the relative path to the tests/ directory cannot be found. You could try changing your build script to use an absolute path. Bitbucket provides access to default variables that can be used to build an absolute path.

    You would change:

    - step:
            name: PyTest
            script:
              - pip install pytest
              - pytest -v tests/* --junitxml=test-reports\report.xml
    

    To something like this (depending on your actual repo directory structure):

    - step:
            name: PyTest
            script:
              - pip install pytest
              - pytest -v ${BITBUCKET_CLONE_DIR}/your/path/to/tests/* --junitxml=test-reports\report.xml
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum