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

ModuleNotFoundError when using python -mcoverage run #925

Closed
joren485 opened this issue Jan 24, 2020 · 1 comment
Closed

ModuleNotFoundError when using python -mcoverage run #925

joren485 opened this issue Jan 24, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@joren485
Copy link

Description

Using python -mcoverage run throws a ModuleNotFoundError error, while using coverage run does not. I use poetry as a dependency and virtual environment manager.

To Reproduce

What version of Python are you using?

$ poetry run python --version
Python 3.8.1

What version of coverage.py are you using?

$ poetry run coverage debug sys
-- sys -------------------------------------------------------
                        version: 5.0.3
                       coverage: /home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/coverage/__init__.py
                         tracer: -none-
                        CTracer: available
           plugins.file_tracers: -none-
            plugins.configurers: -none-
      plugins.context_switchers: -none-
              configs_attempted: .coveragerc
                                 setup.cfg
                                 tox.ini
                                 pyproject.toml
                   configs_read: /tmp/Website/pyproject.toml
                    config_file: None
                config_contents: -none-
                      data_file: -none-
                         python: 3.8.1 (default, Jan  8 2020, 23:09:20) [GCC 9.2.0]
                       platform: Linux-5.4.13-arch1-1-x86_64-with-glibc2.2.5
                 implementation: CPython
                     executable: /home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/bin/python
                   def_encoding: utf-8
                    fs_encoding: utf-8
                            pid: 141790
                            cwd: /tmp/Website
                           path: /home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/bin
                                 /usr/lib/python38.zip
                                 /usr/lib/python3.8
                                 /usr/lib/python3.8/lib-dynload
                                 /home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages
                                 /home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/src/django-admin-autocomplete-filter
                    environment: -none-
                   command_line: /home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/bin/coverage debug sys
                sqlite3_version: 2.6.0
         sqlite3_sqlite_version: 3.30.1
        sqlite3_compile_options: COMPILER=gcc-9.2.0
                                 ENABLE_COLUMN_METADATA
                                 ENABLE_DBSTAT_VTAB
                                 ENABLE_FTS3
                                 ENABLE_FTS3_TOKENIZER
                                 ENABLE_FTS4
                                 ENABLE_FTS5
                                 ENABLE_JSON1
                                 ENABLE_RTREE
                                 ENABLE_UNLOCK_NOTIFY
                                 HAVE_ISNAN
                                 MAX_EXPR_DEPTH=10000
                                 MAX_VARIABLE_NUMBER=250000
                                 SECURE_DELETE
                                 TEMP_STORE=1
                                 THREADSAFE=1

What versions of what packages do you have installed?

$ poetry run pip freeze
appdirs==1.4.3
asgiref==3.2.3
attrs==19.3.0
beautifulsoup4==4.8.2
black==19.10b0
certifi==2019.11.28
chardet==3.0.4
Click==7.0
coverage==5.0.3
Django==3.0.2
-e git+https://github.com/farhan0581/django-admin-autocomplete-filter.git@2f4f80bfca31426faf1b7dab3f8366296f4fe67e#egg=django_admin_autocomplete_filter
django-appconf==1.0.3
django-bootstrap4==1.1.1
django-compressor==2.4
django-sass-processor==0.8
entrypoints==0.3
Faker==4.0.0
flake8==3.7.9
flake8-import-order==0.18.1
freezegun==0.3.14
idna==2.8
libsass==0.19.4
mccabe==0.6.1
pathspec==0.7.0
Pillow==7.0.0
pycodestyle==2.5.0
pydocstyle==5.0.2
pyflakes==2.1.1
python-dateutil==2.8.1
pytz==2019.3
rcssmin==1.0.6
regex==2020.1.8
requests==2.22.0
rjsmin==1.1.0
six==1.14.0
snowballstemmer==2.0.0
soupsieve==1.9.5
sqlparse==0.3.0
text-unidecode==1.3
toml==0.10.0
typed-ast==1.4.1
urllib3==1.25.8

What code are you running?
The master branch of GipHouse/Website.

What commands did you run?
The following steps show how to reproduce the problem.

$ cd /tmp/
$ git clone https://github.com/GipHouse/Website.git
...
$ cd Website
$ poetry install
...
$ poetry run coverage run website/manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
...........................................................................................................................................
----------------------------------------------------------------------
Ran 139 tests in 3.484s

OK
Destroying test database for alias 'default'...
$ poetry run python -mcoverage run website/manage.py test
Traceback (most recent call last):
  File "website/manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
    super().run_from_argv(argv)
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/core/management/base.py", line 320, in run_from_argv
    parser = self.create_parser(argv[0], argv[1])
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/core/management/base.py", line 294, in create_parser
    self.add_arguments(parser)
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/core/management/commands/test.py", line 44, in add_arguments
    test_runner_class = get_runner(settings, self.test_runner)
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/test/utils.py", line 301, in get_runner
    test_runner_class = test_runner_class or settings.TEST_RUNNER
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/conf/__init__.py", line 76, in __getattr__
    self._setup(name)
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/conf/__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/joren/.cache/pypoetry/virtualenvs/giphousewebsite-PQqkI1vM-py3.8/lib/python3.8/site-packages/django/conf/__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'giphousewebsite'

Expected Behavior

python -mcoverage run and coverage run should both succeed and have the same output.

Additional Context

I noticed a similar problem in #862, but that issue was fixed in 5.0.3 (which I am using).

@joren485 joren485 added the bug Something isn't working label Jan 24, 2020
@joren485
Copy link
Author

The problem turned out to be a __init__.py file in the root directory of the Django project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant