question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting per-test environment variables does not merge with per-suite envs & leaks to next test

See original GitHub issue

Cypress 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

Screen Shot 2020-07-16 at 12 08 57 PM

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bahmutovcommented, Jan 12, 2022

Huzza, I mean ohhh

Sent from my iPhone

On Jan 12, 2022, at 10:34, Emily Rohrbough @.***> wrote:

@bahmutov I was able to confirm the issues / scenarios included on this issue with Cypress 9.2.1. This is still an issue.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

1reaction
theKasheycommented, Feb 9, 2022

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.js

I can see a test covering Second problem added back in the original PR, and wondering why the second problem might exist.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found