-2

I wanted to use coveragepy combine to seperate .coverage files into one.

For that I installed python and the coverage module via pip, afterwards then running this command. python -m coverage combine .coverage-*. That should work and does, but aparrently requires either root or for the user to own the directory. So I decided to use sudo within the github action, since I read that it's passwordless.

But when running the installed module with sudo in front of the command it says /usr/bin/python: No module named coverage.

This is the part of my workflow responsible for the actions explained above:

      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          python-version: "3.10"

      - name: Install coverage
        run: |
          python -m pip install --upgrade pip
          pip install coverage

      - name: Listing all items in data directory (Testing)
        run: ls -Al ./docker/data/coverage

      - name: Merge coverage reports
        working-directory: ./docker/data/coverage
        run: sudo python -m coverage combine .coverage-*

running the sudo python -m coverage combine .coverage-* on my local machine works just fine.

Is there any way I can get python to recognise that, that module exists and is installed or is there maybe any other workaround I could use?

3
  • 1
    Please include your relevant GHA workflow in your question along with the commands that work fine on your local machine. Thanks! Commented Apr 7, 2023 at 15:17
  • If you use sudo then Python accesses a different set of packages (site-packages) doesn't it? What was more concretely the issue (error message if any) when running without sudo (it is not described in the question)? Also I would suggest to use a virtual environment to improve the ease of reproducibility. Commented Apr 7, 2023 at 15:39
  • Well yes, apparently, I just didn't realise that. This is the error when running without sudo Couldn't use data file '/home/runner/work/repo/repo/docker/data/coverage/.coverage': unable to open database file. And when it comes to virtual environments, I don't know much about them nor how exactly im suppossed to use them in this kind of situation. But I might look into it if you could elaborate a little more. Commented Apr 7, 2023 at 15:46

1 Answer 1

1

I suspect pip is installing coverage to the user directory. If you must run the command with sudo, try running the pip install with sudo as well.

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

1 Comment

All right will give it a try, thank you

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.