I have a very odd issue that only effects one test case out of 31 for this app.
This one test access a single page, uses selenium.send_keys to enter some data into a form, and then uses selenium.click to click a submit button.
I have confirmed that the test case can see the test data as expected, and when the get method fires on the View (a subclass of a simple View - not anything more complex), the data is visible - all this get method does is serve a page which displays a simple form (not a modelform) and the ‘get’ method doesn’t use or modify the data in anyway.
When the test script fires the submit button, the post method on the view fires as expected, but now the ORM appears entirely empty - i.e. doing an objects.all() on the relevant model returns an empty query set.
Other test cases within the 31 tests for this app also access get and post methods on different views, and in all of those cases the get and post methods can see the expected data in the ORM.
I have confirmed :
- The test case, the get and post are using the same server (determined by looking at the IP-port of the url being accessed).
- The test data is correct in the test and get method and empty in the post method - by using the same line of code.
- The test script does not change the data between invoking the get and invoking the post methods - in fact within the test script the data is correct both before and after the ‘submit’ is clicked (i know that threading likely means the post method is going to run sometime after.
The code being executed is pretty complex so providing here wont help, but i am struggling to understand how to further debug this issue. If i try to put a debugger break-point on the post method I can confirm that in this test case the ORM is empty.
The strange thing is that this view works fine in manual testing - it is only when using automated testing that the test case fails with no data.
The app uses a postGreSQL database
To Add to the mystery - the test case now executes correctly (although the code in the view is broken - but that is my issue) - The post method clearly can see the data view the ORM - nothing changed as far as I can see. It was failing in this same way for 6 or so hours yesterday, and another 2 this morning, and now - suddently - it is ok.
If anyone does have an explanation i would love to know.