The project has so many modules. There are functional test cases being written for almost every api written like for GET requests, POST requests and PUT requests. To test an individual file we use the syntact pytest tests/file_name.py but I want to test a specific method in that file. Is there any way to test it like that??
Asked
Active
Viewed 32 times
1 Answers
0
Duplicate of Is there a way to specify which pytest tests to run from a file?
In a few words, you can use the -k option of pytest to specify the name of the test you would like to run.

Toadster
- 16
- 3
-
So in my case , there are some methods like test_login_user_successful(),test_login_user_unsuccessful(),test_refresh_successful(),get_username() in test_users.py file. I want to test get_username() method. How would that be tested – Sai Naveen Aug 04 '22 at 12:56
-
Have you tried: `pytest tests/file_name.py -k 'test_get_username'` ? I wonder if your issue isn't the missing prefix for your test. All pytest's tests MUST be preceded by 'test_' otherwise it's not concidered as a test. – Toadster Aug 04 '22 at 14:11
-
If your tests are enclosed in a test suite class, use `pytest tests/file_name.py -k '
.test_get_username'` – Toadster Aug 04 '22 at 14:20 -
Yes issue is that I havent mentioned test as a prefix!! My bad! – Sai Naveen Aug 05 '22 at 05:52