We are trying to run django tests through bazel. bazel test ... command is working fine but bazel coverage ... fails with error
ModuleNotFoundError: No module named 'settings'
Traceback (most recent call last):
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/qureai/packages/python/image_manager/tests/main.py", line 13, in
execute_from_command_line(
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/core/management/base.py", line 346, in run_from_argv
parser = self.create_parser(argv[0], argv[1])
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/core/management/base.py", line 320, in create_parser
self.add_arguments(parser)
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/core/management/commands/test.py", line 44, in add_arguments
test_runner_class = get_runner(settings, self.test_runner)
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/test/utils.py", line 317, in get_runner
test_runner_class = test_runner_class or settings.TEST_RUNNER
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/execroot/qureai/bazel-out/k8-fastbuild/bin/packages/python/image_manager/image_manager_test.runfiles/python_deps_django/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/tmp/arunkant/bazel/_bazel_arunkant/e454b3605424c5208f266bd2853bae79/external/python3_9_x86_64-unknown-linux-gnu/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'settings'
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
🐞 bug report
Affected Rule
The issue is caused by the rule: py_test
Is this a regression?
Don't know
Description
We are trying to run django tests through bazel.
bazel test ...command is working fine butbazel coverage ...fails with error🔬 Minimal Reproduction
🔥 Exception or Error
🌍 Your Environment
Operating System:
Output of
bazel version:Rules_python version:
Anything else relevant?
If bazel test works then I expect bazel coverage to work with it