Why is it important to keep the test environment separate from the production environment?
Think about what could happen if test data mixes with real user data.
Separating test and production environments protects real users from test errors and keeps live data safe.
What will be the output of this Python code snippet simulating environment setup?
import os os.environ['ENV'] = 'test' if os.getenv('ENV') == 'test': print('Running in test environment') else: print('Running in production')
Check what value is set for the 'ENV' variable before the condition.
The environment variable 'ENV' is set to 'test', so the condition is true and prints the test message.
Given this configuration snippet for a test environment, which option correctly fixes the error causing tests to connect to production database?
config = {
'database_url': 'prod-db.example.com',
'environment': 'test'
}
# Tests should connect to 'test-db.example.com' insteadCheck which database URL the tests are currently using and what they should use.
The tests connect to the database URL specified in 'database_url'. Changing it to the test database fixes the issue.
Which assertion correctly verifies that the environment variable 'MODE' is set to 'testing' in Python?
import os os.environ['MODE'] = 'testing'
Remember the difference between assignment (=) and comparison (==) in assertions.
Option B correctly compares the environment variable value to 'testing'. Option B uses assignment which is invalid in assert.
In a Continuous Integration/Continuous Deployment (CI/CD) pipeline, what is the best practice to ensure the test environment is correctly set up before running automated tests?
Think about automation and consistency in CI/CD pipelines.
Automating environment setup with code ensures consistent, repeatable test environments and reduces human error.