Setting per-test environment variables does not merge with per-suite envs & leaks to next test
See original GitHub issueCypress v4.10.0
Reproduction https://github.com/cypress-io/cypress-example-recipes recipe examples/server-communication__env-variables spec file
The test sets per-suite environment variables and per-test environment variables.
context('Suite env variables', {
env: {
suiteApi: 'https://staging.dev',
commonFlag: 'suite',
},
}, () => {
it('has all environment variables', () => {
expect(Cypress.env('suiteApi')).to.equal('https://staging.dev')
})
// NOTE: does not work, seems test variables override
// the suite variables but in a weird way (even after commenting out and
// reloading the old variable is still there!)
it.only('has test-specific env variables', {
env: {
testFlag: 42,
commonFlag: 'test',
},
}, () => {
expect(Cypress.env('testFlag'), 'test level variable').to.equal(42)
expect(Cypress.env('commonFlag'), 'test overrides suite').to.equal('test')
expect(Cypress.env('suiteApi'), 'suite level variable').to.equal('https://staging.dev')
})
})
I expect the final Cypress.env
object to have the variables from both the suite and the test itself
But it does not have suite variables

Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Pytest running doesn't take into consideration env. #6891
Test discovery and running have the enviroment variables declared in the .env file or the terminal.integrated.env.linux settings before ...
Read more >python - pytest does not pass along environment variables for ...
I'm not sure why these two have a different scope but you can try to set them both to session or module :...
Read more >How to Mock Environment Variables in pytest - Adam Johnson
Sometimes tests need to change environment variables. This is fairly straightforward in pytest, thanks to os.environ quacking like a dict, ...
Read more >Environment Variables in Next.js - Frontend Digest
We can combine that with our already existing environment variables to set the replacement values to our environment variable values. module.exports = {...
Read more >Configuration - Starlette
Configuration should be stored in environment variables, or in a ".env" file that is not committed to source control. app.py:.
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 Free
Top 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
Huzza, I mean ohhh
Sent from my iPhone
Oh, hopefully, that’s just a bug. I was going to apply some terrible workarounds to play around this limitation. As I understand the problem - it’s as simple as adding a missing use case for the
First Problem
at https://github.com/cypress-io/cypress/blob/1305cca9f19a1dd15851a3830209ba7597404777/packages/driver/cypress/integration/e2e/testConfigOverrides_spec.jsI can see a test covering
Second problem
added back in the original PR, and wondering why the second problem might exist.