4

On Github Action workflow main.yml, I did the following to add to PYTHONPATH

PWD=$(pwd)
export PYTHONPATH=$PWD/src:$PWD/tests:$PYTHONPATH

I verified the PYTHONPATH using the following command

echo "PYTHONPATH=$PYTHONPATH"

and the output is PYTHONPATH=/home/runner/work/my_api/my_api/src:/home/runner/work/my_api/my_api/tests

I have a module called my_api live under /home/runner/work/my_api/my_api/src

But now I'm getting ModuleNotFoundError: No module named 'my_api' It seems export PYTHONPATH has no impact on the system. Below is the complete workfile YML file.

name: Integration Test Run
env:
    HISTORIC_DATA_FOLDER: /usr/my_api_historic_data
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install Python 3
        uses: actions/setup-python@v1
        with:
          python-version: 3.6
      - name: Filessytem Setup
        run: |
          pwd
          mkdir my_api_historic_data_test
      - name: Docker Compose
        run: |
          sudo docker-compose -f docker-compose-github.yml build
          sudo docker-compose -f docker-compose-github.yml --verbose --env-file .env up &
      - name: Intgration Test Setup
        run: |
          echo "-----pwd-----"
          pwd

          echo "-----ls-----"
          ls

          echo "-----ls src/-----"
          ls src/

          echo "----PYTHONPATH------"
          PWD=$(pwd)
          export PYTHONPATH=$PWD/src:$PWD/tests:$PYTHONPATH
          echo "PYTHONPATH=$PYTHONPATH"

          echo "-----HISTORIC PATH----"
          export HISTORIC_DATA_FOLDER=/home/runner/work/my_api/my_api/my_api_historic_data_test
          echo "HISTORIC_DATA_FOLDER=$HISTORIC_DATA_FOLDER"
      - name: Integreation Test Run
        run: |
          sleep 30
          pip install requests
          sudo python -m unittest discover


1
  • 1
    Each named part has it's own environment. You need to 'merge' 'test setup' and 'test run'. Commented Dec 19, 2021 at 21:09

1 Answer 1

5

As already said in comments, each step runs in it's own shell. You need to make sure your variable is exported properly, so that it's available in all subsequent steps.

echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV

See docs for more details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.