Skip to content

Commit 0033093

Browse files
committed
tests/end2end: run each test's SDoc server from its folder, unless specified otherwise
This is a cleaner approach for sandboxing the test environment and its outputs. The optional cwd= parameter is forward-looking and will be used for testing the Diff screen feature where a custom Git tree setup must be done in a temporary folder.
1 parent 34a0a7b commit 0033093

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tests/end2end/server.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import psutil
2323
from psutil import NoSuchProcess
2424

25+
from strictdoc import environment
2526
from strictdoc.helpers.file_system import get_portable_temp_dir
2627
from tests.end2end.conftest import test_environment
2728

@@ -86,12 +87,16 @@ def __init__(
8687
config_path: Optional[str] = None,
8788
port: Optional[int] = None,
8889
expectations: Optional[List] = None,
90+
cwd: Optional[str] = None,
8991
):
9092
is_parallel_execution = test_environment.is_parallel_execution
9193

9294
assert os.path.isdir(input_path)
9395
if config_path is not None:
94-
assert os.path.exists(config_path)
96+
assert os.path.exists(config_path), config_path
97+
if cwd is not None:
98+
assert os.path.isdir(cwd), cwd
99+
95100
self.path_to_tdoc_folder = input_path
96101
self.output_path: Optional[str] = output_path
97102
self.config_path: Optional[str] = config_path
@@ -123,6 +128,11 @@ def __init__(
123128
else ["INFO: Application startup complete."]
124129
)
125130

131+
self.cwd: str = cwd if cwd is not None else input_path
132+
self.path_to_strictdoc: str = os.path.join(
133+
environment.path_to_strictdoc, "strictdoc/cli/main.py"
134+
)
135+
126136
# All of these below become initialized/used starting from run()
127137
self.process = None
128138
self.log_file_out = None
@@ -161,6 +171,7 @@ def run(self):
161171
stdout=self.log_file_out.fileno(),
162172
stderr=subprocess.PIPE,
163173
shell=False,
174+
cwd=self.cwd,
164175
env=strictdoc_env,
165176
)
166177
self.process = process
@@ -285,9 +296,7 @@ def get_host_and_port(self):
285296

286297
def _get_strictdoc_command(self) -> Tuple[List[str], Dict[str, str]]:
287298
should_collect_coverage = test_environment.coverage
288-
strictdoc_args = [
289-
sys.executable,
290-
]
299+
strictdoc_args: List[str] = [sys.executable]
291300
if should_collect_coverage:
292301
strictdoc_args.extend(
293302
[
@@ -302,7 +311,7 @@ def _get_strictdoc_command(self) -> Tuple[List[str], Dict[str, str]]:
302311

303312
strictdoc_args.extend(
304313
[
305-
"strictdoc/cli/main.py",
314+
self.path_to_strictdoc,
306315
"server",
307316
"--no-reload",
308317
"--port",

0 commit comments

Comments
 (0)