Skip to content

Commit

Permalink
Merge 51ecdc0 into 585c2ee
Browse files Browse the repository at this point in the history
  • Loading branch information
ilaner committed Apr 9, 2024
2 parents 585c2ee + 51ecdc0 commit 4ec910d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .changelog/4219.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Fixed an issue where tests were not collected in VSCode after **setup-env**
type: fix
pr_number: 4219
19 changes: 14 additions & 5 deletions demisto_sdk/commands/setup_env/setup_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

BACKUP_FILES_SUFFIX = ".demisto_sdk_backup"
DOTENV_PATH = CONTENT_PATH / ".env"
DOTENV_DOCKER_PATH = CONTENT_PATH / ".env.docker"


class IDEType(Enum):
Expand Down Expand Up @@ -278,12 +279,12 @@ def configure_module_discovery(ide_type: IDEType):
ide_folder = CONTENT_PATH / ".vscode"
ide_folder.mkdir(exist_ok=True, parents=True)
configure_vscode_settings(ide_folder=ide_folder)
# Delete PYTHONPATH and MYPYPATH from env file because they are not needed
env_file = CONTENT_PATH / ".env"
env_vars = dotenv.dotenv_values(env_file)
env_vars["PYTHONPATH"] = PYTHONPATH_STR
update_dotenv(DOTENV_PATH, env_vars)
env_vars.pop("PYTHONPATH", None)
env_vars.pop("MYPYPATH", None)
update_dotenv(env_file, env_vars)
update_dotenv(DOTENV_DOCKER_PATH, env_vars)

if ide_type == IDEType.PYCHARM:
python_discovery_paths = PYTHONPATH.copy()
Expand Down Expand Up @@ -326,6 +327,7 @@ def build_tasks():
"env": {
"PYTHONPATH": ":".join(docker_python_path),
},
"envFiles": [str(DOTENV_DOCKER_PATH)],
},
},
{
Expand All @@ -350,6 +352,7 @@ def build_tasks():
],
"customOptions": f"-w /app/{integration_script.path.parent.relative_to(CONTENT_PATH.absolute())}",
"env": {"PYTHONPATH": ":".join(docker_python_path)},
"envFiles": [str(DOTENV_DOCKER_PATH)],
},
},
],
Expand Down Expand Up @@ -413,7 +416,7 @@ def build_launch():
},
{
"name": "Python: Debug Integration locally",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": f"/workspaces/content/{integration_script.path.relative_to(CONTENT_PATH)}"
if devcontainer
Expand All @@ -425,7 +428,7 @@ def build_launch():
},
{
"name": "Python: Debug Tests",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
Expand Down Expand Up @@ -640,6 +643,11 @@ def configure_params(
values={"DEMISTO_PARAMS": json.dumps(params)},
quote_mode="never",
)
update_dotenv(
file_path=DOTENV_DOCKER_PATH,
values={"DEMISTO_PARAMS": json.dumps(params)},
quote_mode="never",
)
except SecretManagerException:
logger.warning(
f"Failed to fetch integration params for '{secret_id}' from Google Secret Manager."
Expand Down Expand Up @@ -753,6 +761,7 @@ def configure_integration(
)

if create_virtualenv and integration_script.type.startswith("python"):
(base_path / ".vscode" / "launch.json").unlink(missing_ok=True)
pack = integration_script.in_pack
assert isinstance(pack, Pack), "Expected pack"
base_path = pack.path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_setup_env_vscode(mocker, monkeypatch, pack, create_virtualenv):
)
dotenv_text = (repo_path / ".env").read_text()
assert "DEMISTO_PARAMS" in dotenv_text
assert "PYTHONPATH" not in dotenv_text
assert "PYTHONPATH" in dotenv_text
vscode_folder = (
repo_path / ".vscode" if not create_virtualenv else Path(pack.path) / ".vscode"
)
Expand Down

0 comments on commit 4ec910d

Please sign in to comment.