se2p / pynguin

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

pynguin does not finish. Does not point to the piece of code that caused a problem #28

Closed HourGlss closed 1 year ago

HourGlss commented 2 years ago

windows, python 3.10.5, pynguin version 0.25.2 using a venv not shared with other projects. (venv) PS C:\Users\xxxxx\PycharmProjects\Fighting> pynguin --project-path . --output_path ./test --module_name main_one_file ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ C:\Python\Python310\lib\runpy.py:196 in _run_module_as_main │ │ │ │ 193 │ main_globals = sys.modules["__main__"].__dict__ │ │ 194 │ if alter_argv: │ │ 195 │ │ sys.argv[0] = mod_spec.origin │ │ ❱ 196 │ return _run_code(code, main_globals, None, │ │ 197 │ │ │ │ │ "__main__", mod_spec) │ │ 198 │ │ 199 def run_module(mod_name, init_globals=None, │ │ │ │ C:\Python\Python310\lib\runpy.py:86 in _run_code │ │ │ │ 83 │ │ │ │ │ __loader__ = loader, │ │ 84 │ │ │ │ │ __package__ = pkg_name, │ │ 85 │ │ │ │ │ __spec__ = mod_spec) │ │ ❱ 86 │ exec(code, run_globals) │ │ 87 │ return run_globals │ │ 88 │ │ 89 def _run_module_code(code, init_globals=None, │ │ │ │ C:\Users\xxxxx\PycharmProjects\Fighting\venv\Scripts\pynguin.exe\__main__.py:7 in <module> │ │ │ │ [Errno 2] No such file or directory: │ │ 'C:\\Users\\xxxxx\\PycharmProjects\\Fighting\\venv\\Scripts\\pynguin.exe\\__main__.py' │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\cli.py:190 in main │ │ │ │ 187 │ set_configuration(parsed.config) │ │ 188 │ if console is not None: │ │ 189 │ │ with console.status("Running Pynguin..."): │ │ ❱ 190 │ │ │ return run_pynguin().value │ │ 191 │ else: │ │ 192 │ │ return run_pynguin().value │ │ 193 │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\generator.py:107 in │ │ run_pynguin │ │ │ │ 104 │ """ │ │ 105 │ try: │ │ 106 │ │ _LOGGER.info("Start Pynguin Test Generation…") │ │ ❱ 107 │ │ return _run() │ │ 108 │ finally: │ │ 109 │ │ _LOGGER.info("Stop Pynguin Test Generation…") │ │ 110 │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\generator.py:330 in _run │ │ │ │ 327 │ │ executor, test_cluster, constant_provider │ │ 328 │ ) │ │ 329 │ _LOGGER.info("Start generating test cases") │ │ ❱ 330 │ generation_result = algorithm.generate_tests() │ │ 331 │ if algorithm.resources_left(): │ │ 332 │ │ _LOGGER.info("Algorithm stopped before using all resources.") │ │ 333 │ else: │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\generation\algorithms\dyn │ │ amosastrategy.py:70 in generate_tests │ │ │ │ 67 │ │ │ self.create_test_suite(self._archive.solutions) │ │ 68 │ │ ) │ │ 69 │ │ while self.resources_left() and len(self._archive.uncovered_goals) > 0: │ │ ❱ 70 │ │ │ self.evolve() │ │ 71 │ │ │ self.after_search_iteration(self.create_test_suite(self._archive.solutions)) │ │ 72 │ │ │ │ 73 │ │ self.after_search_finish() │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\generation\algorithms\dyn │ │ amosastrategy.py:84 in evolve │ │ │ │ 81 │ │ """Runs one evolution step.""" │ │ 82 │ │ offspring_population: list[ │ │ 83 │ │ │ tcc.TestCaseChromosome │ │ ❱ 84 │ │ ] = self._breed_next_generation() │ │ 85 │ │ │ │ 86 │ │ # Create union of parents and offspring │ │ 87 │ │ union: list[tcc.TestCaseChromosome] = [] │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\generation\algorithms\abs │ │ tractmosastrategy.py:60 in _breed_next_generation │ │ │ │ 57 │ │ │ │ offspring_population.append(offspring_1) │ │ 58 │ │ │ │ │ 59 │ │ │ # Apply mutation on offspring_2 │ │ ❱ 60 │ │ │ self._mutate(offspring_2) │ │ 61 │ │ │ if offspring_2.has_changed() and offspring_2.size() > 0: │ │ 62 │ │ │ │ offspring_population.append(offspring_2) │ │ 63 │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\generation\algorithms\abs │ │ tractmosastrategy.py:85 in _mutate │ │ │ │ 82 │ │ │ 83 │ @staticmethod │ │ 84 │ def _mutate(offspring: tcc.TestCaseChromosome) -> None: │ │ ❱ 85 │ │ offspring.mutate() │ │ 86 │ │ if not offspring.has_changed(): │ │ 87 │ │ │ # if offspring is not changed, we try to mutate it once again │ │ 88 │ │ │ offspring.mutate() │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\ga\testcasechromosome.py: │ │ 122 in mutate │ │ │ │ 119 │ │ │ randomness.next_float() │ │ 120 │ │ │ <= config.configuration.search_algorithm.test_delete_probability │ │ 121 │ │ ): │ │ ❱ 122 │ │ │ if self._mutation_delete(): │ │ 123 │ │ │ │ changed = True │ │ 124 │ │ │ │ 125 │ │ if ( │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\ga\testcasechromosome.py: │ │ 159 in _mutation_delete │ │ │ │ 156 │ │ │ if idx >= self.size(): │ │ 157 │ │ │ │ continue │ │ 158 │ │ │ if randomness.next_float() <= p_per_statement: │ │ ❱ 159 │ │ │ │ changed |= self._delete_statement(idx) │ │ 160 │ │ return changed │ │ 161 │ │ │ 162 │ def _delete_statement(self, idx: int) -> bool: │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\ga\testcasechromosome.py: │ │ 164 in _delete_statement │ │ │ │ 161 │ │ │ 162 │ def _delete_statement(self, idx: int) -> bool: │ │ 163 │ │ assert self._test_factory, "Mutation requires a test factory." │ │ ❱ 164 │ │ modified = self._test_factory.delete_statement_gracefully(self._test_case, idx) │ │ 165 │ │ return modified │ │ 166 │ │ │ 167 │ def _mutation_change(self) -> bool: │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\testcase\testfactory.py:6 │ │ 64 in delete_statement_gracefully │ │ │ │ 661 │ │ changed = False │ │ 662 │ │ if variable is not None: │ │ 663 │ │ │ for i in range(position + 1, test_case.size()): │ │ ❱ 664 │ │ │ │ alternatives = test_case.get_objects(variable.type, i) │ │ 665 │ │ │ │ try: │ │ 666 │ │ │ │ │ alternatives.remove(variable) │ │ 667 │ │ │ │ except ValueError: │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\testcase\testcase.py:254 │ │ in get_objects │ │ │ │ 251 │ │ │ var = statement.ret_val │ │ 252 │ │ │ if var is None: │ │ 253 │ │ │ │ continue │ │ ❱ 254 │ │ │ if not var.is_none_type() and is_consistent_with(var.type, parameter_type): │ │ 255 │ │ │ │ variables.append(var) │ │ 256 │ │ │ │ 257 │ │ return variables │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\utils\type_utils.py:162 │ │ in is_consistent_with │ │ │ │ 159 │ │ typ1 is typing.Any or typ2 is typing.Any │ │ 160 │ ): # pylint:disable=comparison-with-callable │ │ 161 │ │ return True │ │ ❱ 162 │ return is_subtype_of(typ1, typ2) │ │ 163 │ │ 164 │ │ 165 def extract_non_generic_class(obj) -> type | None: │ │ │ │ c:\users\xxxxx\pycharmprojects\fighting\venv\lib\site-packages\pynguin\utils\type_utils.py:136 │ │ in is_subtype_of │ │ │ │ 133 │ ) is not None: │ │ 134 │ │ # Hacky way to handle generics by trying to extract non-generic classes │ │ 135 │ │ # and checking for subclass relation │ │ ❱ 136 │ │ return issubclass(non_generic_tp1, non_generic_tp2) │ │ 137 │ if is_union_type(typ2): │ │ 138 │ │ if is_union_type(typ1): │ │ 139 │ │ │ # Union[int, str] is a subtype of Union[str, float, int] │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: issubclass() argument 2 cannot be a parameterized generic

Any help would be great. Thanks!

stephanlukasczyk commented 2 years ago

Hi, Could you please try again with Pynguin's latest release (0.26.0)? If it still fails, we would like to ask you for a minimal subject file that produces this error as well as the used parametres to Pynguin to allow us to reproduce the issue.