Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest


@pytest.fixture
def isolated_test_env(tmp_path):
project_dir = tmp_path / "project"
global_dir = tmp_path / "global"
project_dir.mkdir()
global_dir.mkdir()

Check warning on line 9 in tests/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/conftest.py#L6-L9

Added lines #L6 - L9 were not covered by tests

return {

Check warning on line 11 in tests/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/conftest.py#L11

Added line #L11 was not covered by tests
"project_dir": project_dir,
"global_dir": global_dir
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping the globa vs. project configs here...
I believe that for the purpose of integration testing we could simplify this to just use the
tmp_path / zowe.config.json

Suggested change
project_dir = tmp_path / "project"
global_dir = tmp_path / "global"
project_dir.mkdir()
global_dir.mkdir()
return {
"project_dir": project_dir,
"global_dir": global_dir
}
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 tmp_path

Copy link
Contributor Author

@rohansen856 rohansen856 May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zFernand0 @pem70 I think instead of tmp_path we need to return the config_file and config_path variables from the function. It would look something like this:

from pathlib import Path

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
    }

And for the other file (tests/integration/test_integration_env.py):

def test_isolated_env_does_not_touch_real_home(isolated_test_env):
    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()

And yes this simplifies the overall structure by isolating all the logic and assertions in different functions🫡. Please let me know if I am mistaken anywhere...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is alright then we can possibly move towards making the structure more modular by using it like this: class TestIsolatedEnv(unittest.TestCase): as you suggested. A step by step approach would be better so I would like to first make a commit for modifications as mentioned above then move towards the modular integration...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zFernand0 is it ok to require zowe.config.json to be at the root level of the project, or should we allow it to reside at any folder level?

17 changes: 17 additions & 0 deletions tests/integration/test_integration_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pathlib import Path


def test_isolated_env_does_not_touch_real_home(isolated_test_env):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Does this actually verify that the environment does not touch the "real home"?
  • When you mean "real home," are you referring to the user's home directory? or ZOWE_CLI_HOME?

project_dir = isolated_test_env["project_dir"]
global_dir = isolated_test_env["global_dir"]

# Copy contets of the actual zowe.config.json as it's necessary for the test
real_config_path = Path(__file__).resolve().parent.parent.parent / "zowe.config.json"

assert real_config_path.exists(), f"Missing config at {real_config_path}"

config_file = project_dir / "zowe.config.json"
config_file.write_text(real_config_path.read_text())

assert config_file.exists()
assert "profiles" in config_file.read_text()
Loading