TestProject Forum

Pytest does not discover genereated python code

I downloaded a test that is working as expected in the WebUI as python code.
Unfortunately pytest cannot find it.

Ok, my bad. Partly. :slight_smile:

Test filenames are expected to start with the test_
Which means that the downloaded zip from app.testproject.io should follow that convention.


Hi Stefanos!
I am hoping I understood your question.

To my knowledge there is more than one way to execute a pytest test.
Assuming you are using the terminal/cmd:
One of the ways is to prefix the python module with a ‘test_’ prefix.
Another way is to tell pytest which python module you would like to run:
For example: pytest my_generated_test_name.py

If you are using PyCharm you can simply add a new ‘Run/Debug Configuration’ of type pytest that will point to the module you want to test.

However, pytest do search for methods starting with ‘test_’ because these are the methods that it will test.
You can see that the test method in the generated code is always named: “test_main”.

Hi Tzah,

Many thanks for getting back to me about this.

One of the ways is to prefix the python module with a ‘test_’ prefix.
Exactly, that was the part I was missing.

My suggestion would be to adjust the “export code” action from the Web App, to produce a python test file with its name starting with ‘test_’; this is not the case at the moment. The option of naming explicitly which python file to run is fine, but with more folders and files it would become a bit tedious to name them all.

What do you think?

Makes sense overall.

I think this kind of change can’t hurt.
Let me discuss this with my team and see if there is any objection.
If there is no response in here by the end of day, make sure to ping us another comment.


1 Like

Got the OK, we will add the “test_” prefix to the generated test files.

I will update you when the new version of the Python Code Generator is out.

Fantastic! Looking forward!