Skip to content

Cannot generate tests when user code calls function from another module #1562

@tyuldashev

Description

@tyuldashev

Description

In case code uses method from another file then Python UTBot cannot generate test due cannot find that module.

To Reproduce

Steps to reproduce the behavior:

  1. Create two py files with following code:
# file a
def sum(a, b):
    return a + b

#-------------------------------------------------
# file b
import a


def double_sum(n):
    return a.sum(n, n)
  1. Generate tests for double_sum(n)

Expected behavior

Tests are generated

Actual behavior

No matter what state of Visit only specified source option tests are not generated.

Visual proofs (screenshots, logs, images)
image

idea.log is full with such errors:

2022-12-21 17:42:25,539 [1904978]   INFO - STDOUT - | UtBot - PythonEngine              | Error evaluation: 1, , [Traceback (most recent call last):,   File "C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-191213119845437442179195\2008_run_double_sum.py", line 4, in <module>,     from mod1.b import *,   File "C:\Users/t00814305/IdeaProjects/Python/Python3\mod1\b.py", line 1, in <module>,     import a, ModuleNotFoundError: No module named 'a']

Additional context

Once I've got a bit different errors in idea.log, but cannot reproduce it now. isArmstrong is a function I was testing:

2022-12-21 17:29:06,337 [1105776]   INFO - STDOUT - | UtBot - PythonEngine              | Error evaluation: 1, , [Traceback (most recent call last):,   File "C:\Users\T00814~1\AppData\Local\Temp\UTBot\python-test-generation-78110564449218154754105\867_run_isArmstrong.py", line 8, in <module>,     isArmstrong,,     ^^^^^^^^^^^, NameError: name 'isArmstrong' is not defined]

Metadata

Metadata

Assignees

Labels

ctg-bugIssue is a buglang-pythonIssue is related to python supportstatus-verifiedBug fix is verified

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions