| __pycache__ |
| """ base init class, changing the bash environment for process """ | |
| import os | |
| from unittest import TestCase | |
| class BaseTests(TestCase): | |
| """Large framework base utilities""" | |
| def setUp(self): | |
| print("setUp in BaseTests") | |
| super().setUp() | |
| self.original_env = os.environ.copy() | |
| # change an exesting environment variable for all tests | |
| os.environ["SHELL"] = "/bin/foo" | |
| print("--- environ in process ---") | |
| print(os.environ) | |
| def tearDown(self): | |
| os.environ = self.original_env | |
| print("--- restored environ ---") | |
| print(os.environ) | |
| super().tearDown() | |
| """ Real test class impacted by the presence of A """ | |
| from . import BaseTests | |
| import os | |
| import subprocess | |
| class B(BaseTests): | |
| @classmethod | |
| def setUpClass(cls): | |
| super().setUpClass() | |
| print("\n------------------------------\nRemoving http_proxy env variable for all tests of this class") | |
| cls.proxy_env = os.environ.pop("http_proxy", None) | |
| @classmethod | |
| def tearDownClass(cls): | |
| super().tearDownClass() | |
| if cls.proxy_env: | |
| os.environ["http_proxy"] = cls.proxy_env | |
| def test_foo(self): | |
| env_output = subprocess.check_output(["env"]).decode("utf-8") | |
| print("--- env subprocess ---") | |
| print(env_output) | |
| self.assertNotIn("http_proxy=", env_output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment