3

I have an API server build using EVE framework. I am using py.test framework for testing. I came across a weird problem.

If I test my APIs using flask's test_client I get unpredictable results. i.e. If I run py.test command 3 times in a row, back to back (without any changes to tests) from the terminal, I get different results e.g.

3 passed, 5 failed 
5 passed, 3 failed
8 passed, 0 failed

The tests that fail with 404 for the URL (resource endpoint)

If I use requests library instead of the test_client, everything works correctly, i.e. 8 passed every time I run the tests.

I have a code similar to the following :

client = app.test_client()

# POST_METHOD = client.post
# BASE_URL = '/'
# GET_METHOD = client.get

POST_METHOD = requests.post
BASE_URL = 'http://' + app.config.get('SERVER_NAME') + '/'
GET_METHOD = requests.get
...
...
...
url = BASE_URL + 'resource1'
...
...
r = POST_METHOD(url, data=json.dumps(somedata), headers=headers)

I can consistently reproduce this problem, by simply switching the commented and uncommented code from the top 3 lines, and using test_client instead of requests

I had initially thought that this is something to do with timing (test_client tests running faster than requests) But 404 is baffling. Why would an endpoint vanish ?

--

this may be related, but the token is not part of my URL. It is part of the header.

Mandar Vaze
  • 1,324
  • 13
  • 20

0 Answers0