Issue Running Unittests on GitHub Actions - ImportError

Hello,

I’m encountering an issue running unit tests for my Django project on GitHub Actions. The tests run fine on my local machine using Docker containers, but I’m facing errors when running tests on GitHub Actions.

Issue Description:

In my CI/CD configuration file (GitHub Actions), I encounter an error when attempting to run tests. Here is a snippet of the error I’m receiving:

======================================================================
ERROR: AHC_app.AHC_app (unittest.loader._FailedTest.AHC_app.AHC_app)
----------------------------------------------------------------------
ImportError: Failed to import test module: AHC_app.AHC_app
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/unittest/loader.py", line 429, in _find_test_path
    package = self._get_module_from_name(name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/unittest/loader.py", line 339, in _get_module_from_name
    __import__(name)
ModuleNotFoundError: No module named 'AHC_app.AHC_app'

What I’ve Tried:

  1. Setting PYTHONPATH: I’ve experimented with different configurations for the PYTHONPATH environment variable to point to the module locations, but I encounter the same error. Below are some examples of configurations I’ve tried:

  2. init.py Files: I verified that all necessary init.py files are present, confirming the project structure is correct.

What I Need Help With:

Has anyone experienced similar issues with importing modules when running tests on GitHub Actions? What could be causing the ModuleNotFoundError, and what are best practices for configuring PYTHONPATH in the context of GitHub Actions?

Additional Context:

I am using Docker Compose for containerization and optionally deploying Kubernetes on Minikube.

Files:

GitHub Actions Configuration File

Thank you in advance for any assistance!

  1. Verify the PYTHONPATH Setting: Ensure that the PYTHONPATH environment variable is correctly set to include the path to your AHC_app module. The path should point to the directory containing the __init__.py file for your module. In your case, it should be /home/runner/work/Animals_Healthcare_Application/Animals_Healthcare_Application/AHC_app.

  2. Review the Module Structure: Verify that your module structure is correct. Ensure that the AHC_app module is in the correct location and that the __init__.py file is present in the directory.

  3. Use Absolute Imports: Instead of using relative imports, try using absolute imports to ensure that the correct module is being imported. For example, instead of from AHC_app import AHC_app, use from Animals_Healthcare_Application.AHC_app import AHC_app.