-
Notifications
You must be signed in to change notification settings - Fork 539
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
Cannot load Python modules if they are in a directory named "test" #874
Comments
Hello @jzvikart, Thank you for creating this issue and we will look into it :) |
Hello @jzvikart 👋 , The issue you're experiencing arises from a naming conflict with Python's standard library. More specifically, test is a package in Python's standard library, and when you run The differences you're noticing between your local Python environment and the GitHub Actions environment are likely due to variations in how the Python interpreter is invoked and the specific environment configurations. Here are a couple of potential workarounds:
- name: Set up
run: |
mkdir test
echo "print('OK')" > test/a.py
touch test/__init__.py If an
- name: Run Fail
working-directory: ./test
run: python -m a
Please note that these are potential workarounds. The underlying behavior is due to the specific mechanisms of Python's import system and how it interacts with the I hope this provides a clearer explanation of the issue. Feel free to reach out if you need any further clarification. |
@priyagupta108 There is no such Python standard library "test". As I mentioned, in a standard Python installation (not via GH action setup-python) there is no problem having a test directory named "test". In other words, this problem is specific to GH action setup-python. |
@jzvikart, The discrepancy you're noticing between standard Python installation and the GitHub Actions environment can be due to a variety of factors, such as differences in the Python interpreter, the way the Python environment is set up, the way the PYTHONPATH is configured, etc. The initial idea of requiring |
Thanks, I know about that package, but as you can read it's for internal use only and not a standard library. However, that's besides the point. The main point is that The solution to rename directory is obvious, but counterintuitive. The name "test" would be quite a common one I imagine. As for |
I agree that
Also, you might find this related Stack Overflow issue helpful: Running unittest with typical test directory structure |
Hello @jzvikart , |
In the following workflow, the step "Run OK" succeeds, but the step "Run Fail" fails.
The only difference is the name of the directory (
test
vs.test1
).As much as I tried, setting
PYTHONPATH
did not help to fix the last step.Outputs:
Needless to say, in normal Python installations the problem does not occur and both
test
andtest1
work.The text was updated successfully, but these errors were encountered: