Why should a test automation project read configuration like base URLs and credentials from environment variables instead of hardcoding them in test files?
Answer
Hardcoded URLs and credentials tie every test run to one specific environment and force editing test source code just to point the suite at staging versus production versus a local instance, and hardcoded secrets risk being committed to version control. Reading configuration through `os.environ` (often loaded from a local `.env` file with a library like `python-dotenv` for developer convenience) lets the exact same test code run unmodified against any target environment, with secrets supplied by a CI system's secret store rather than ever appearing in the repository.
Strong answer includes
- hardcoding ties test runs to one environment and risks committing secrets
- os.environ lets the same test code target any environment unmodified
- secrets come from a CI secret store, never from source-controlled files
Practical example
BASE_URL = os.environ["BASE_URL"]read once at the top of a test config module lets the exact same suite run against `https://staging.example.com` or `https://example.com` purely by changing an environment variable in the CI job, never the test code.