From 18fcc07c7796889fe1cc4bc86564459ccd387ae7 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 25 May 2023 16:56:14 +0100 Subject: Tests: unified setup method usage. To make fixtures accessible inside of setup methods in tests all these methods are renamed to the "setup_method_fixture" and decorated by autouse flag. Also all setup methods moved to the top of the files. --- test/test_static.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'test/test_static.py') diff --git a/test/test_static.py b/test/test_static.py index f7eade7c..48004661 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -3,21 +3,21 @@ import socket import pytest from unit.applications.proto import TestApplicationProto -from unit.option import option from unit.utils import waitforfiles class TestStatic(TestApplicationProto): prerequisites = {} - def setup_method(self): - os.makedirs(f'{option.temp_dir}/assets/dir') - with open(f'{option.temp_dir}/assets/index.html', 'w') as index, open( - f'{option.temp_dir}/assets/README', 'w' - ) as readme, open( - f'{option.temp_dir}/assets/log.log', 'w' - ) as log, open( - f'{option.temp_dir}/assets/dir/file', 'w' + @pytest.fixture(autouse=True) + def setup_method_fixture(self, temp_dir): + os.makedirs(f'{temp_dir}/assets/dir') + assets_dir = f'{temp_dir}/assets' + + with open(f'{assets_dir}/index.html', 'w') as index, open( + f'{assets_dir}/README', 'w' + ) as readme, open(f'{assets_dir}/log.log', 'w') as log, open( + f'{assets_dir}/dir/file', 'w' ) as file: index.write('0123456789') readme.write('readme') @@ -27,9 +27,7 @@ class TestStatic(TestApplicationProto): self._load_conf( { "listeners": {"*:7080": {"pass": "routes"}}, - "routes": [ - {"action": {"share": f'{option.temp_dir}/assets$uri'}} - ], + "routes": [{"action": {"share": f'{assets_dir}$uri'}}], "settings": { "http": { "static": { -- cgit