Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 9

pythonpackage.yml workflow doesn't install my package before running its tests?

So I tried Github Actions for the first time, with the Python packageworkflow option. The tests fail because it can't import my package. 

 

___________________ ERROR collecting tests/test_something.py ____________________

ImportError while importing test module '/home/runner/work/my_package/my_package/tests/test_something.py'.

Hint: make sure your test modules/packages have valid Python names.

Traceback:

tests/test_something.py:7: in <module>

from my_package import something

E ModuleNotFoundError: No module named 'my_package'

 

Either I have to

 

1. Tell the pythonpackage.yml to install my package before running the tests?  `pip install .` or something?  But if this is correct, why isn't it already there?

2. Change my package so it doesn't need to be installed in order for tests to run?  Am I not following best practices?

8 Replies
GitHub Partner
Message 2 of 9

Re: pythonpackage.yml doesn't install my package before running its tests?

When you want to use Python in the workflow runs on GitHub-hosted runner, you should use the setup-python action to set up a Python environment at first. And before building and testing your code, you may also need to install some dependencies from the PyPI package registry by using the pip install.
More details about using Python with GitHub Actions, you can reference here: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-python-with-gi...

If you still have questions for this ticket, can you share more details of your workflow definition and the completed debug logs of the workflow run?

Copilot Lvl 2
Message 3 of 9

Re: pythonpackage.yml doesn't install my package before running its tests?

I'm just using the default pythonpackage.yml.  I think it's ultimately from https://github.com/actions/starter-workflows/blob/master/ci/python-package.yml ?

 

Actions.png

 

Yes, it installs python and dependencies from requirements.txt correctly, but doesn't install the actual package itself.  I'm not sure if it's supposed to, or if my tests should run without installing the package.

Copilot Lvl 2
Message 4 of 9

Re: pythonpackage.yml doesn't install my package before running its tests?

In this article they run tests that just import from a module that is in the same folder, which wouldn't require installing first: https://realpython.com/python-continuous-integration/

 

Is that what it expects we're doing?

 

In scipy the tests actually import scipy, though, which would require it to be installed:

https://github.com/scipy/scipy/blob/master/scipy/signal/tests/test_dltisys.py

Copilot Lvl 2
Message 5 of 9

Re: pythonpackage.yml doesn't install my package before running its tests?

Hi @endolith 

 

Do you have an example run/yaml file or repo where you're runing into this issue? I can quickly take a look and try to figure out why your package isn't being installed. The error message you have might be somehow related:

make sure your test modules/packages have valid Python names

 

The basic pythonpackage.yml sample doesn't take into account any extra packages that your project or repository requires. It's meant to serve as a template/example to get you up and running. I would make sure that any extra package or dependency that you need gets installed either through pip or by adding it to requirements.txt

 

There are a lot of ways to setup tests with Python, but generally what I've seen is you first install all depedencies which include any packages, and then you run tests. If a specific package isn't installed and a test requires that package, then the test will fail.

 

 

 

 

 

Copilot Lvl 2
Message 6 of 9

Re: pythonpackage.yml doesn't install my package before running its tests?

Ok I made it public: https://github.com/endolith/elsim

 

https://github.com/endolith/elsim/blob/master/.github/workflows/pythonpackage.yml

 

There's no line in the default workflow that installs the package itself, which makes me wonder if I'm doing the tests wrong.

 

https://github.com/endolith/elsim/runs/390504822

Copilot Lvl 2
Message 7 of 9

Re: pythonpackage.yml doesn't install my package before running its tests?

This one had `python setup.py install` and then changed it to `pip install .`:

https://github.com/havakv/pycox/commit/9a8fd8e9f93ee73f514515c899b32f721798a722#diff-fd3c00174dcaf7b...


It has a similar tests folder structure and imports as mine.


This one added `pip install -e .`:

https://github.com/hofstee/shale/commit/7a7f4f245d020522c5c3892511768d222f77e303#diff-fd3c00174dcaf7...


This one has `pip install -e .[test]` and similar folders and imports:

https://github.com/Zsailer/nbclassic/blob/master/.github/workflows/pythonpackage.yml


This one doesn't install the package either, I'm not sure how it is passing:

https://github.com/mattblaha/readability-selenium/blob/master/.github/workflows/pythonpackage.yml

unittest works differently from pytest?

Copilot Lvl 2
Message 8 of 9

Re: pythonpackage.yml doesn't install my package before running its tests?

Ok I got it to pass by adding that:

 

https://github.com/endolith/elsim/commit/6646ccb25c019e5accfd0429951a81a2f9356b18

 

It still has problems, though.  numba doesn't work in the Github Actions environment even though it works fine locally:

 

/opt/hostedtoolcache/Python/3.7.6/x64/lib/python3.7/site-packages/llvmlite/ir/instructions.py:84: in __init__
    raise TypeError(msg)
E   TypeError: Failed in nopython mode pipeline (step: nopython mode backend)
E   Type of #4 arg mismatch: i1 != i32

Possibly related to https://github.com/numba/numba/issues/5035

 

It also doesn't understand tests_require?

 

 
Run pip install -e .[test]

Obtaining file:///home/runner/work/elsim/elsim

WARNING: elsim 0.1.0 does not provide the extra 'test'

 

 

Also WTF does this forum not use Markdown like every other place on Github?

Copilot Lvl 2
Message 9 of 9

Re: pythonpackage.yml doesn't install my package before running its tests?

Glad you got it mostly working 😀

 

Seems to me like you're mostly having configuration issues. Python can have a lot of annoying little configuration issues that can be hard/difficult to find.

 

I would suggest trying to add an empty __init__.py file in your tests/ directory, some information about what this file is: https://pythontips.com/2013/07/28/what-is-__init__-py/

https://stackoverflow.com/questions/448271/what-is-init-py-for

 

Not including this has the potential for certain things not to be found and installed. If you have this file, you may not need to do pip install -e 🤞

 

I'm honestly not all that familiar with unittest (there are ALOT of different testing frameworks/tools for Python) but I'm sure it has some differences when compared to pytest.

 

Regarding markdown not being used here, I'll try to pass on the feedback to the appropriate team! Different teams work on different products and github.community is separate from the base github.com