-
Notifications
You must be signed in to change notification settings - Fork 35
feat: added pytest fixture to create and use its own temporary directory structure #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
7a369d5
699a81d
b342ee1
7757c2e
ae79b01
e2ea9d9
fc9df2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||
| from unittest import TestCase | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import pytest | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @pytest.fixture | ||||||||||||||||||||||||||||||
| def isolated_test_env(tmp_path): | ||||||||||||||||||||||||||||||
| config_path = Path(__file__).resolve().parent.parent.parent / "zowe.config.json" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| config_file = tmp_path / "zowe.config.json" | ||||||||||||||||||||||||||||||
| config_file.write_text(config_path.read_text()) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||
| "config_path": config_path, | ||||||||||||||||||||||||||||||
| "config_file": config_file | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| class TestIsolatedEnv(unittest.TestCase): | ||||||||||||||||||||||||||||||
| """Base class for isolated test environments.""" | ||||||||||||||||||||||||||||||
| @pytest.fixture(autouse=True) | ||||||||||||||||||||||||||||||
| def _setup_test_env(self, isolated_test_env): | ||||||||||||||||||||||||||||||
| self.isolated_test_env = isolated_test_env | ||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+24
|
||||||||||||||||||||||||||||||
| class TestIsolatedEnv(unittest.TestCase): | |
| """Base class for isolated test environments.""" | |
| @pytest.fixture(autouse=True) | |
| def _setup_test_env(self, isolated_test_env): | |
| self.isolated_test_env = isolated_test_env | |
| @pytest.fixture(autouse=True) | |
| def _setup_test_env(isolated_test_env): | |
| """Automatically set up the isolated test environment.""" | |
| return isolated_test_env | |
| class TestIsolatedEnv(unittest.TestCase): | |
| """Base class for isolated test environments.""" | |
| def setUp(self): | |
| self.isolated_test_env = _setup_test_env(isolated_test_env) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| """Test isolated environment setup for integration tests.""" | ||
|
|
||
| def test_isolated_env_does_not_touch_real_home(isolated_test_env): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| config_path = isolated_test_env["config_path"] | ||
| config_file = isolated_test_env["config_file"] | ||
|
|
||
| assert config_path.exists(), f"Missing config at {config_path}" | ||
| assert config_file.exists() | ||
| assert "profiles" in config_file.read_text() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inheriting from unittest.TestCase while using pytest fixtures may lead to unexpected test collection behavior; consider defining TestIsolatedEnv as a plain class or using pytest’s xunit setup hooks instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider this comment as we don't want this to negatively impact test collection behavior. Maybe we can pursue those xunit setup hooks.