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

I want to test flask package with pynguin, however pynguin cannot deal with relative imports (i.e., cannot import relative modules of flask). Can you give me some advice on how to solve this problem? #80

Open khangtran2020 opened 4 days ago

khangtran2020 commented 4 days ago

I want to test flask package with pynguin, however pynguin cannot deal with relative imports (i.e., cannot import relative modules of flask). Can you give me some advice on how to solve this problem?

stephanlukasczyk commented 4 days ago

Could you provide me a minimal working example, please, that exhibits the behaviour? I have zero experience with Flask, thus need something to work with. Please also specify versions of Python, Pynguin, and dependencies, as well as everything else that would be needed to reproduce the issue.

khangtran2020 commented 4 days ago

Thank you for your response. I clone the flask repo here: https://github.com/pallets/flask

Then I run:

pynguin --project-path ./src/flask --output-path ../test --module-name cli

And get this error:

ImportError: attempted relative import with no known parent package

Wooza commented 3 days ago

AFAIK, Pynguin adds the directory specified with 'project-path' to sys.path. So you have to use the following command for your example: pynguin --project-path ./src/ --output-path ../test --module-name flask.cli

stephanlukasczyk commented 14 hours ago

Did @Wooza 's suggestion resolve the issue, @khangtran2020 ?