se2p / pynguin

The PYthoN General UnIt Test geNerator is a test-generation tool for Python
https://www.pynguin.eu
MIT License
1.24k stars 76 forks source link

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

Open distort5871 opened 6 months ago

distort5871 commented 6 months ago

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):

Additional information:

darklambda commented 4 months ago

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:

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!