summaryrefslogtreecommitdiffhomepage
path: root/test/conftest.py
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2023-03-07 14:47:39 +0000
committerAndrei Zeliankou <zelenkov@nginx.com>2023-03-07 14:47:39 +0000
commit4ed4283cffe86a9ec942e59a1f686fd8286b7398 (patch)
treecde27f35bcda698bcfc7546f88b52d057786ddd7 /test/conftest.py
parentd13c4fb5036380e86b595e694f8e1ab16804db88 (diff)
downloadunit-4ed4283cffe86a9ec942e59a1f686fd8286b7398.tar.gz
unit-4ed4283cffe86a9ec942e59a1f686fd8286b7398.tar.bz2
Tests: _clear_temp_dir() function introduced.
Also added temporary directory clearing after checking available modules to prevent garbage environment when tests start.
Diffstat (limited to '')
-rw-r--r--test/conftest.py57
1 files changed, 31 insertions, 26 deletions
diff --git a/test/conftest.py b/test/conftest.py
index 8944c6b3..5dc92fa2 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -232,6 +232,8 @@ def pytest_sessionstart(session):
if option.restart:
shutil.rmtree(unit_instance['temp_dir'])
+ else:
+ _clear_temp_dir()
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
@@ -316,32 +318,7 @@ def run(request):
if not option.restart:
_clear_conf(f'{unit["temp_dir"]}/control.unit.sock', log=log)
-
- if is_findmnt and not waitforunmount(unit['temp_dir'], timeout=600):
- exit('Could not unmount some filesystems in tmp dir.')
-
- for item in os.listdir(unit['temp_dir']):
- if item not in [
- 'control.unit.sock',
- 'state',
- 'unit.pid',
- 'unit.log',
- ]:
- path = os.path.join(unit['temp_dir'], item)
-
- public_dir(path)
-
- if os.path.isfile(path) or stat.S_ISSOCK(os.stat(path).st_mode):
- os.remove(path)
- else:
- for attempt in range(10):
- try:
- shutil.rmtree(path)
- break
- except OSError as err:
- if err.errno != 16:
- raise
- time.sleep(1)
+ _clear_temp_dir()
# check descriptors
@@ -564,6 +541,34 @@ def _clear_conf(sock, *, log=None):
assert 'success' in resp, 'remove certificate'
+def _clear_temp_dir():
+ temp_dir = unit_instance['temp_dir']
+
+ if is_findmnt and not waitforunmount(temp_dir, timeout=600):
+ exit('Could not unmount some filesystems in tmpdir ({temp_dir}).')
+
+ for item in os.listdir(temp_dir):
+ if item not in [
+ 'control.unit.sock',
+ 'state',
+ 'unit.pid',
+ 'unit.log',
+ ]:
+ path = os.path.join(temp_dir, item)
+ public_dir(path)
+ if os.path.isfile(path) or stat.S_ISSOCK(os.stat(path).st_mode):
+ os.remove(path)
+ else:
+ for attempt in range(10):
+ try:
+ shutil.rmtree(path)
+ break
+ except OSError as err:
+ if err.errno != 16:
+ raise
+ time.sleep(1)
+
+
def _check_processes():
router_pid = _fds_info['router']['pid']
controller_pid = _fds_info['controller']['pid']