Fixture returns outdated/false data
See original GitHub issueCurrent behavior:
Reading and writing fixtures seems to not work as expected (please let me know if this is my error). Across two different tests (within the same spec) the returned value from cy.fixture
is outdated and should have been updated by a previous call to cy.writeFile
. This looks to me like a caching issue?
Desired behavior:
It should always return the latest data from the fixture and not something outdated.
Steps to reproduce: (app code and test code)
- Create a empty spec and paste the below code.
- Run the spec and see the output in the dashboard.
describe('fixture', () => {
it('step 1', () => {
// Create the fixture first
cy.writeFile("cypress/fixtures/test-temp.json", {
id: 1,
name: 'Step 1'
});
// Let's see the data, it should be fine
cy.fixture("test-temp").then(data => cy.log(data));
// Update the fixture again
cy.writeFile("cypress/fixtures/test-temp.json", {
id: 1,
name: 'Step 2'
});
});
it('step 2', () => {
// Let's wait 5 seconds just to be sure
cy.wait(5000);
// The returned data is { id: 1, name: 'Step 1' }
// Should be { id: 1, name: 'Step 2' }
cy.fixture("test-temp").then(data => cy.log(data));
});
});
Versions
Cypress 3.4.0 & 3.3.2 MacOS Mojave Chrome 75
UPDATE: No need to create 2 different tests, it also happens inside the very same test.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:27 (3 by maintainers)
Top Results From Across the Web
How can I use return of fixture function and data which will be ...
I found answer as fixture function will be given as a test argument: @pytest.mark.parametrize("name,surname,age",test_data) def ...
Read more >pytest fixtures: explicit, modular, scalable
Once pytest finds them, it runs those fixtures, captures what they returned (if anything), and passes those objects into the test function as...
Read more >Pytest - Fixtures - Tutorialspoint
Therefore, instead of running the same code for every test, we can attach fixture function to the tests and it will run and...
Read more >fixture | Cypress Documentation
Load a fixed set of data located in a file. Syntax Usage Correct Usage Arguments filePath ... Using null explicitly will return the...
Read more >pytest-cases
New current_cases fixture to easily know the current case for each parameter ! ... def user_bob(): return "bob" @parametrize_with_cases("data", cases='.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So I asked the team about this. We are indeed caching the reference to the fixture to save memory. This was intended at the time, but is likely not a great solution now.
We likely need to rework this logic, to not use the cache when the file has been changed. We can detect that the file has changed by initially getting the SHA, compare if SHA has changed, otherwise use cache. Alternatively look at modifiedAt time of the file (if works on all platforms)
Workaround:
You can use
cy.readFile()
instead of fixture as this will not use the cacheing.I don’t really see a case for changing fixtures. Fixtures is something prepared in advance and shouldn’t change. If you want to randomize test data, you need
faker
or something.Change fixtures to match changes made by API requests? Do you even need fixtures in this case? To answer that question I need more details. What data you have in fixtures? What requests you make?
The bottom line is if you need to change fixtures, that’s most likely a sign you’re doing something wrong. Or so I think for now.