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

Pls help, Error: No moduled named xx is not a package #67

Open
distort5871 opened this issue May 10, 2024 · 1 comment
Open

Pls help, Error: No moduled named xx is not a package #67

distort5871 opened this issue May 10, 2024 · 1 comment

Comments

@distort5871
Copy link

Describe the bug
No moduled Named xx is not a package

To Reproduce
Steps to reproduce the behaviour:

  1. Use Pynguin version '3.10'
  2. Use the following (minimal) code as a subject for test generation:

import cacheops
from cacheops.utils import carefully_strip_whitespace

  1. Use the following command line arguments to Pynguin: pynguin --project-path ./django-cacheops/cacheops/templatetags --output-path ./pynguin-results --module-name cacheops'
  2. Give the error (stack trace, etc) you are encountering: '

│ C:\Users\x\AppData\Local\anaconda3\envs\ccpy10\lib\site-packages\pynguin\generator.py:163 in _load_sut │ │ │ │ 160 │ try: │ │ 161 │ │ # We need to set the current thread ident so the import trace is recorded. │ │ 162 │ │ tracer.current_thread_identifier = threading.current_thread().ident │ │ ❱ 163 │ │ importlib.import_module(config.configuration.module_name) │ │ 164 │ except ImportError as ex: │ │ 165 │ │ # A module could not be imported because some dependencies │ │ 166 │ │ # are missing or it is malformed │ │ │ │ C:\Users\x\AppData\Local\anaconda3\envs\ccpy10\lib\importlib\__init__.py:126 in import_module │ │ │ │ 123 │ │ │ if character != '.': │ │ 124 │ │ │ │ break │ │ 125 │ │ │ level += 1 │ │ ❱ 126 │ return _bootstrap._gcd_import(name[level:], package, level) │ │ 127 │ │ 128 │ │ 129 _RELOADING = {} │ │ in _gcd_import:1050 │ │ in _find_and_load:1027 │ │ in _find_and_load_unlocked:1006 │ │ in _load_unlocked:688 │ │ │ │ C:\Users\x\AppData\Local\anaconda3\envs\ccpy10\lib\site-packages\pynguin\instrumentation\machinery.py:59 in exec_module │ │ │ │ 56 │ │ │ 57 │ def exec_module(self, module): # noqa: D102 │ │ 58 │ │ self._tracer.reset() │ │ ❱ 59 │ │ super().exec_module(module) │ │ 60 │ │ self._tracer.store_import_trace() │ │ 61 │ │ │ 62 │ def get_code(self, fullname) -> CodeType: │ │ in exec_module:883 │ │ in _call_with_frames_removed:241 │ │ │ │ C:\Users\x\Documents\self\github.com\./django-cacheops/cacheops/templatetags\cacheops.py:8 in <module> │ │ │ │ 5 from django.template.library import TagHelperNode, parse_bits │ │ 6 │ │ 7 import cacheops │ │ ❱ 8 from cacheops.utils import carefully_strip_whitespace │ │ 9 │ │ 10 │ │ 11 __all__ = ['CacheopsLibrary', 'invalidate_fragment'] │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ModuleNotFoundError: No module named 'cacheops.utils'; 'cacheops' is not a package

Expected behavior
How to solve this problem?
Or what can i do to generate test case for this project:django-cacheops

Screenshots

  1. Errormsg
    errormsg

  2. Project
    project

Software Version (please complete the following information):

  • OS: Windows
  • Python version [3.10.14]
  • Pynguin Version [pynguin 0.36.0 pyhd8ed1ab_0 conda-forge]

Additional information:

  • I use this project to test if pynguin can generate test code for complicated project, maybe it will help you : django-cacheops
@darklambda
Copy link

darklambda commented Jul 1, 2024

Hi,
I think I managed to make Pynguin recognize the module (cacheops.templatetags.cacheops) and somehow start reading the Project. For it, I used the following steps:

  • Worked with Poetry. This means that I installed poetry in my local machine and called poetry install in Pynguin's root folder.
  • Called poetry shell to activate poetry's virtual env.
  • Called pip install {package} for the packages "funcy", "django" and "redis".
  • Cloned the repository with git clone {url} in a directory that I named ".../Modules"
  • Called `poetry run pynguin --project-path .../Modules/django-cacheops --output-path [YourPath] --module-name cacheops.templetags.cacheops --algorithm MIO --coverage-metrics BRANCH

Nonetheless, this got me into a problem, to which I am not sure if there's a clear turnaround. Apparently, to execute some methods in the Cacheops Project, you need to already have a Django Project set up, as one of them is asking for a configuration in the settings file. I tried creating a new site with django-admin startproject mysite and adding the path to the settings.py file (created after calling python manage.py runserver) into the virtual env /bin/activate file, but had no luck.
Hope this can help you a bit.

Best wishes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants