kondratyev-nv / vscode-python-test-adapter

Python Test Adapter for the VS Code Test Explorer
https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter
MIT License
117 stars 27 forks source link

Error in test_ #248

Closed Ch1lled closed 3 years ago

Ch1lled commented 3 years ago

I have several files with test for one api. One of the tests returns json. When I try to use it as a variable in tests from other files Test Explorer shows that there is an "Error in test_%testname%.py" and there are no Run | Debug | ... buttons in this tests. изображение_2021-05-26_180830

kondratyev-nv commented 3 years ago

@Ch1lled Thank you for the issue! Error in <test file name> usually means there are some errors in this file detected on the test discovery stage (invalid syntax, import of missing module, etc). You can click on that test and you should see an actual error in Output panel.

Ch1lled commented 3 years ago

@Ch1lled Thank you for the issue! Error in <test file name> usually means there are some errors in this file detected on the test discovery stage (invalid syntax, import of missing module, etc). You can click on that test and you should see an actual error in Output panel.

If I don't use json from new_user test it's alright and if I click on "Debug this test" there are no issues with both "broken" tests while running. But thanks, I'll try to find something wrong with my code.

kondratyev-nv commented 3 years ago

I can assume that there is something wrong with importing a method or this "variable from other file". Do you see an actual error in the Output panel? Additionally, you can try verifying your code by doing test discovery/execution from the command line. Anyway, feel free to reopen the issue if you find out any new details.

Ch1lled commented 3 years ago

To import I simply use this: import test_api_lk_new_user as new_user user = new_user.test_new_user() user_id = user['user_id'] phone = user['phone']

And yeah, there is an error in Output panel, but it's an error in new_user that totally runs without issues while runnig alone or in debug mode.

kondratyev-nv commented 3 years ago

Can you post the error here? It'd be easier to identify the issue that way. Have you tried running test_api_lk_login from the command line?

Ch1lled commented 3 years ago

test_api_lk_login.py:14: in user = new_user.test_new_user() test_api_lk_new_user.py:24: in test_new_user assert response_body['status'] == 1 E assert 0 == 1

If I run the login test using pytest .\test_api_lk_login.py it's is ok.

kondratyev-nv commented 3 years ago

I see. This happens because you're using new_user.test_new_user() in the global scope, which is executed during the test discovery stage. And assert is triggered as there is probably some setup (or mocking) missing at that stage. Consider wrapping this in some kind of function and call this function in tests. Let me know if this helps.

Ch1lled commented 3 years ago

Made a separate user creation function and with its import it finally works, thanks a lot.