From f761cbf56c1abfc210dfaa5ea0f06ca06d6d1a15 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sat, 18 Jun 2022 22:15:20 -0400 Subject: [PATCH] Setup temporary directories to run tests. --- .gitignore | 1 + tests/step_defs/server.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e9868bd..64fb936 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target *.swp +tests/data diff --git a/tests/step_defs/server.py b/tests/step_defs/server.py index 44bd6e2..573c1fd 100644 --- a/tests/step_defs/server.py +++ b/tests/step_defs/server.py @@ -2,7 +2,10 @@ from asyncio import create_subprocess_exec, get_event_loop, sleep from pathlib import Path +from random import choices +from shutil import rmtree from socket import gethostname, gethostbyname, socket +from string import ascii_lowercase class Server: @@ -10,6 +13,8 @@ class Server: def __init__(self): """Initialization of a server.""" + self.datadir = Path.cwd().joinpath("tests", "data", "".join(choices(ascii_lowercase, k=5))) + self.datadir.mkdir(parents=True) self.env = {} self.process = None self.loop = get_event_loop() @@ -42,9 +47,10 @@ class Server: async def __start(self): """async start of the server.""" - print(self.env) self.process = await create_subprocess_exec( - Path.cwd().joinpath("target", "release", "morethantext_web"), env=self.env + Path.cwd().joinpath("target", "release", "morethantext_web"), + env=self.env, + cwd=self.datadir ) await sleep(1) @@ -65,6 +71,7 @@ class Server: def destroy(self): """Removes the server instance.""" self.stop() + rmtree(self.datadir, ignore_errors=True) def set_safe_port(self): """Set the server port to something not being used."""