Verified Commit f0b88b53 authored by Jan Miksik's avatar Jan Miksik Committed by Jan Miksik
Browse files

Added autoreporting and test repetition

Contents:
- test repetition (--repeat)
- autoreporting

Autoreporting into folder ~/reports (must be already created)
Format of html report:
[DATE]-[TIME]-[TARGET]-[TEST PATH].html
where [TEST PATH] is replaced for mlutiple tests or all
  if not exactly one value is present
parent 0ac39cb7
Pipeline #96934 passed with stages
in 1 minute and 24 seconds
......@@ -8,6 +8,7 @@ import selenium
import nsfarm.target
import nsfarm.web
import time
logger = logging.getLogger(__package__)
......@@ -30,6 +31,17 @@ def pytest_addoption(parser):
help="Run vncviewer when ever we start selenium container.",
action="store_true",
)
parser.addoption(
"--repeat",
default=1,
type=int,
help="Number of times to repeat selected tests",
)
parser.addoption(
"--noreport",
help="Turns off report",
action="store_false",
)
@pytest.hookimpl(tryfirst=True)
......@@ -46,6 +58,18 @@ def pytest_configure(config):
setattr(config, "target_config", targets.get(config.getoption("-T")))
# Set if gui viewer should be open when testing using Selenium
nsfarm.web.Container.open_viewer = config.getoption("--viewgui")
# Add report if tags are not present
if config.getoption("--noreport") and "--html" not in config.option:
filename = time.strftime("%Y-%m-%d-%H%M")
filename += f"-{config.option.target}" if config.option.target else ""
filename += f"-{config.getoption('-B')}" if "branch" in config.option and config.option.branch else ""
if len(config.option.file_or_dir) > 1:
filename += "-partial"
elif len(config.option.file_or_dir) == 1:
filename += "-" + config.option.file_or_dir[0].replace("/", ".").strip(".")
else:
filename += "-full"
config.option.htmlpath = f"~/reports/{filename}.html"
class HTMLReport:
......@@ -84,3 +108,8 @@ def screenshot(record_property):
record_property(f"png.{when}", (name, source.get_screenshot_as_base64()))
return __shot
def pytest_collection_modifyitems(session, config, items):
count = config.option.repeat
session.items[:] = session.items * count # add each test multiple times
[pytest]
addopts = --strict-markers
log_file = test.log
log_file_level = DEBUG
log_file_format = %(levelname)s[%(relativeCreated)d]%(name)s %(message)s
log_file_date_format = %Y/%m/%d %H:%M:%S
log_level = DEBUG
log_format = %(levelname)s[%(relativeCreated)d]%(name)s %(message)s
log_cli_format = %(levelname)s %(name)s %(message)s
......@@ -7,3 +13,4 @@ markers =
deploy: quick tests to be run as part of deployment process
board(boards): mark test to run only on specified boards
not_board(boards): mark test to not run on specified boards
debug: mark used for debugging
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment