Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run pytest as module #108

Closed
wants to merge 1 commit into from
Closed

Run pytest as module #108

wants to merge 1 commit into from

Conversation

RMeli
Copy link
Contributor

@RMeli RMeli commented Jun 8, 2020

I just spent a few hours debugging a ModuleNotFoundError with GitHub Actions. My installed module was not picked up by pytest for some reason and running pytest as a module solved the issue.

Since my GitHub Action was strongly inspired by this one, I think running pytest as a module could be a safer option here as well?

@RMeli
Copy link
Contributor Author

RMeli commented Jun 8, 2020

Pinging @jaimergp as the author of #95

@jaimergp
Copy link
Contributor

jaimergp commented Jun 9, 2020

Hi! Thanks for the report! May I see your GHA implementation? Maybe there's something else going on because we haven't seen this problem in several projects we are using this in!

@RMeli
Copy link
Contributor Author

RMeli commented Jun 9, 2020

Sure, here it is:

name: pytest

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ "**" ]

jobs:
  test:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.6, 3.7, 3.8]

    steps:
    - uses: actions/checkout@v2

    - name: Build infos
      shell: bash
      run: |
        uname -a
        df -h
        ulimit -a

    # More info on options: https://github.com/goanpeca/setup-miniconda
    - uses: goanpeca/setup-miniconda@v1
      with:
        python-version: ${{ matrix.python-version }}
        environment-file: conda.yml
        activate-environment: test
        miniconda-version: "latest"
        auto-update-conda: true
        auto-activate-base: false
        show-channel-urls: true

    - name: Install package
      # conda setup requires this special shell
      shell: bash -l {0}
      run: |
        cd code
        python -m pip install . --no-deps
        python -c "import ael; print(ael)"

    - name: conda infos
      # conda setup requires this special shell
      shell: bash -l {0}
      run: |
        conda info
        conda list
        conda env list

    - name: Run tests
      # conda setup requires this special shell
      shell: bash -l {0}
      run: |
        cd code
        python -m pytest -v --cov=ael --color=yes tests

As I mentioned I did not use the cookiecutter for this particular project, therefore it is very likely I did something wrong in my GHA. However, I think using python -m never hurts.

@jaimergp
Copy link
Contributor

jaimergp commented Jun 9, 2020

I think using python -m never hurts.

Absolutely! We can probably integrate this without much discussion. I don't see anything obviously wrong in your yml so, yep, CI stuff 🤷

Let's see what the MolSSI devs think!

@janash
Copy link
Member

janash commented Jun 9, 2020

I would like to understand the problem/why it occurred. Running pytest as a module adds the current directory to sys.path, so this seems like some kind of package installation issue. I'm not sure of the other consequences of using -m, but am hesitant to add anything without understanding the problem we're solving. Do you have links to the GHA logs?

@RMeli
Copy link
Contributor Author

RMeli commented Jun 9, 2020

@janash I completely understand. Unfortunately I could not troubleshoot why this problem was happening (but the reason it's very likely unrelated to this repository). I don't have a direct link to the GHA log since it's in a private repository, I'll see if I can copy-paste it here.

I tried to troubleshoot the issue for a long time and I observed the following:

  • pip installation was always successful
  • The working directory was the same in which I run test locally (with pytest only)
  • python -c "import ael; print(ael)" always worked after installation, under all name sections
  • My package was always present in conda list after installation

I thought as well about installation issues but what puzzles me is that python -c "import ael; print(ael)" was working.

@RMeli
Copy link
Contributor Author

RMeli commented Jun 9, 2020

(Since this is likely unrelated with the cookiecutter, please feel free to close the PR at any time. I mainly wanted to leave a comment somewhere in case other people encounter similar problems in the future.)

@RMeli RMeli closed this Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants