-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathconftest.py
More file actions
59 lines (48 loc) · 1.9 KB
/
conftest.py
File metadata and controls
59 lines (48 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
from typing import Any, Optional
import pytest
from invoke.config import Config
from invoke.context import Context
os.environ["INCLUDE_WORKSPACE_FILE"] = "false"
class MockContext(Context):
def __init__(self, config: Optional[Config] = None) -> None:
defaults = Config.global_defaults()
defaults["run"]["pty"] = True
defaults["run"]["in_stream"] = False
super().__init__(config=config)
def run(self, command: str, **kwargs: Any):
kwargs["in_stream"] = False
runner = self.config.runners.local(self)
return self._run(runner, command, **kwargs)
@pytest.fixture(autouse=True)
def add_test_to_pythonpath():
"""Add the test directory to PYTHONPATH for all tests."""
test_dir = os.path.dirname(os.path.abspath(__file__))
if test_dir not in sys.path:
sys.path.append(test_dir)
yield
if test_dir in sys.path:
sys.path.remove(test_dir)
@pytest.fixture(autouse=True)
def reset_nemorun_skip_confirmation():
from nemo_run.cli import api
"""Reset NEMORUN_SKIP_CONFIRMATION to None before each test."""
api.NEMORUN_SKIP_CONFIRMATION = None
yield
# Optionally, reset after the test as well
api.NEMORUN_SKIP_CONFIRMATION = None