Skip to content

Commit

Permalink
feature: support pabot
Browse files Browse the repository at this point in the history
If you use the `pabot` library to run tests in parallel, the reporter will send the results
  • Loading branch information
gibiw committed Oct 3, 2024
1 parent 3c59c57 commit ec0b123
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
8 changes: 8 additions & 0 deletions qase-robotframework/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# qase-pytest 3.2.0

## What's new

Minor release that includes all changes from beta versions 3.2.0b.

Support `pabot` library. If you use the `pabot` library to run tests in parallel, the reporter will send the results

# qase-pytest 3.2.0b3

## What's new
Expand Down
3 changes: 2 additions & 1 deletion qase-robotframework/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "qase-robotframework"
version = "3.2.0b3"
version = "3.2.0"
description = "Qase Robot Framework Plugin"
readme = "README.md"
authors = [{name = "Qase Team", email = "[email protected]"}]
Expand All @@ -18,6 +18,7 @@ urls = {"Homepage" = "https://github.com/qase-tms/qase-python/tree/master/qase-r
requires-python = ">=3.7"
dependencies = [
"qase-python-commons~=3.1.3",
"filelock~=3.12.2",
]

[project.optional-dependencies]
Expand Down
56 changes: 52 additions & 4 deletions qase-robotframework/src/qase/robotframework/listener.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
import pathlib
import uuid

from filelock import FileLock
from qase.commons import ConfigManager
from qase.commons.models import Result, Suite, Step, Field
from qase.commons.models.step import StepType, StepGherkinData
from qase.commons.reporters import QaseCoreReporter
from robot.libraries.BuiltIn import BuiltIn

from .filter import Filter
from .plugin import QaseRuntimeSingleton
Expand All @@ -15,15 +18,22 @@
logger = logging.getLogger("qase-robotframework")


def get_pool_id():
return BuiltIn().get_variable_value('${PABOTQUEUEINDEX}', None)


class Listener:
ROBOT_LISTENER_API_VERSION = 3

meta_run_file = pathlib.Path("src.run")

def __init__(self):
config = ConfigManager()
self.reporter = QaseCoreReporter(config)
self.runtime = QaseRuntimeSingleton.get_instance()
self.step_uuid = None
self.tests = {}
self.pabot_index = None

if config.config.debug:
logger.setLevel(logging.DEBUG)
Expand All @@ -34,9 +44,26 @@ def __init__(self):
ch.setFormatter(formatter)
logger.addHandler(ch)

self.reporter.start_run()

def start_suite(self, suite, result):
self.pabot_index = get_pool_id()
if self.pabot_index is not None:
try:
if int(self.pabot_index) == 0:
test_run_id = self.reporter.start_run()
with FileLock("qase.lock"):
if test_run_id:
with open(self.meta_run_file, "w") as lock_file:
lock_file.write(str(test_run_id))
else:
while True:
if Listener.meta_run_file.exists():
self.__load_run_from_lock()
break
except RuntimeError:
logger.error("Failed to create or read lock file")
else:
self.reporter.start_run()

execution_plan = self.reporter.get_execution_plan()
if execution_plan:
selector = Filter(*execution_plan)
Expand Down Expand Up @@ -99,8 +126,15 @@ def end_test(self, test, result):
)

def close(self):
logger.info("complete run executing")
self.reporter.complete_run()
if self.pabot_index is not None:
if int(self.pabot_index) == 0:
Listener.drop_run_id()
else:
self.reporter.complete_worker()

if not Listener.meta_run_file.exists():
logger.info("complete run executing")
self.reporter.complete_run()

def __extract_tests_with_suites(self, suite, parent_suites=None):
if parent_suites is None:
Expand Down Expand Up @@ -184,3 +218,17 @@ def __parse_condition_steps(self, result_step) -> List[Step]:
steps.append(step)

return steps

def __load_run_from_lock(self):
if Listener.meta_run_file.exists():
with open(Listener.meta_run_file, "r") as lock_file:
try:
test_run_id = str(lock_file.read())
self.reporter.set_run_id(test_run_id)
except ValueError:
pass

@staticmethod
def drop_run_id():
if Listener.meta_run_file.exists():
Listener.meta_run_file.unlink()

0 comments on commit ec0b123

Please sign in to comment.