improve reports
This commit is contained in:
parent
878448f654
commit
7e76bedfc7
|
@ -40,7 +40,7 @@ jobs:
|
|||
- run: pip install -r requirements.txt
|
||||
|
||||
- name: Run tests
|
||||
run: pytest -n 3 --reruns 5 --alluredir=allure-results
|
||||
run: pytest -n 3 --reruns 1 --alluredir=allure-results
|
||||
|
||||
- name: Get allure history
|
||||
if: always()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Custom
|
||||
log/
|
||||
.vscode
|
||||
allure-results/
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
|
|
@ -10,7 +10,7 @@ def get_env_var(var_name, default):
|
|||
return env_var
|
||||
|
||||
|
||||
# Configuration constants
|
||||
# Configuration constants. Need to be upercase to appear in reports
|
||||
NODE_1 = get_env_var("NODE_1", "wakuorg/nwaku:deploy-wakuv2-test")
|
||||
NODE_2 = get_env_var("NODE_2", "wakuorg/go-waku:latest")
|
||||
LOG_DIR = get_env_var("LOG_DIR", "./log")
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import logging
|
||||
import os
|
||||
import base64
|
||||
import allure
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def bytes_to_hex(byte_array):
|
||||
|
@ -16,3 +21,8 @@ def to_base64(input_data):
|
|||
input_bytes = str(input_data).encode()
|
||||
base64_encoded = base64.b64encode(input_bytes)
|
||||
return base64_encoded.decode()
|
||||
|
||||
|
||||
def attach_allure_file(file):
|
||||
logger.debug("Attaching file %s", file)
|
||||
allure.attach.file(file, name=os.path.basename(file), attachment_type=allure.attachment_type.TEXT)
|
||||
|
|
|
@ -15,9 +15,9 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class WakuNode:
|
||||
def __init__(self, docker_image, docker_log_sufix=""):
|
||||
def __init__(self, docker_image, docker_log_prefix=""):
|
||||
self._image_name = docker_image
|
||||
self._log_path = os.path.join(LOG_DIR, f"docker_{self._image_name.replace('/', '_')}_{docker_log_sufix}.log")
|
||||
self._log_path = os.path.join(LOG_DIR, f"{docker_log_prefix}__{self._image_name.replace('/', '_')}.log")
|
||||
self._docker_manager = DockerManager(self._image_name)
|
||||
self._container = None
|
||||
self._ext_ip = self._docker_manager.generate_random_ext_ip()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
from time import sleep
|
||||
import pytest
|
||||
import allure
|
||||
from src.env_vars import NODE_1, NODE_2
|
||||
from src.node.waku_node import WakuNode
|
||||
from tenacity import retry, stop_after_delay, wait_fixed
|
||||
|
@ -10,18 +11,19 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
class StepsRelay:
|
||||
@pytest.fixture(scope="function", autouse=True)
|
||||
def setup_nodes(self):
|
||||
self.node1 = WakuNode(NODE_1)
|
||||
def setup_nodes(self, request):
|
||||
self.node1 = WakuNode(NODE_1, request.cls.test_id)
|
||||
self.node1.start(relay="true", discv5_discovery="true", peer_exchange="true")
|
||||
enr_uri = self.node1.info()["result"]["enrUri"]
|
||||
self.node2 = WakuNode(NODE_2)
|
||||
self.node2 = WakuNode(NODE_2, request.cls.test_id)
|
||||
self.node2.start(relay="true", discv5_discovery="true", discv5_bootstrap_node=enr_uri, peer_exchange="true")
|
||||
self.node1.set_subscriptions()
|
||||
self.node2.set_subscriptions()
|
||||
self.default_content_topic = "/test/1/waku-relay"
|
||||
self.default_payload = "Relay works!!"
|
||||
|
||||
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
|
||||
@allure.step
|
||||
@retry(stop=stop_after_delay(2), wait=wait_fixed(0.2), reraise=True)
|
||||
def check_published_message_reaches_peer(self, message):
|
||||
self.node1.send_message(message)
|
||||
sleep(0.1)
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
from src.libs.common import attach_allure_file
|
||||
import src.env_vars as env_vars
|
||||
from src.data_storage import DS
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -17,9 +23,35 @@ def pytest_runtest_makereport(item):
|
|||
return None
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def set_allure_env_variables():
|
||||
yield
|
||||
if os.path.isdir("allure-results") and not os.path.isfile(os.path.join("allure-results", "environment.properties")):
|
||||
with open(os.path.join("allure-results", "environment.properties"), "w") as outfile:
|
||||
for attribute_name in dir(env_vars):
|
||||
if attribute_name.isupper():
|
||||
attribute_value = getattr(env_vars, attribute_name)
|
||||
outfile.write(f"{attribute_name}={attribute_value}\n")
|
||||
|
||||
|
||||
@pytest.fixture(scope="function", autouse=True)
|
||||
def test_setup(request):
|
||||
logger.debug("Running test: %s", request.node.name)
|
||||
def test_id(request):
|
||||
# setting up an unique test id to be used where needed
|
||||
request.cls.test_id = f"{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}__{str(uuid4())}"
|
||||
|
||||
|
||||
@pytest.fixture(scope="function", autouse=True)
|
||||
def test_setup(request, test_id):
|
||||
logger.debug("Running test: %s with id: %s", request.node.name, request.cls.test_id)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function", autouse=True)
|
||||
def attach_logs_on_fail(request):
|
||||
yield
|
||||
if request.node.rep_call.failed:
|
||||
logger.debug("Test failed, attempting to attach logs to the allure reports")
|
||||
for file in glob.glob(os.path.join(env_vars.LOG_DIR, request.cls.test_id + "*")):
|
||||
attach_allure_file(file)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function", autouse=True)
|
||||
|
|
Loading…
Reference in New Issue