Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version_provider = "pep621"
update_changelog_on_bump = false
[project]
name = "pytestomatio"
version = "2.10.2"
version = "2.11.0b2"


dependencies = [
Expand Down
6 changes: 4 additions & 2 deletions pytestomatio/connect/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ def get_tests(self, test_metadata: list[TestItem]) -> dict:
return response.json()

def create_test_run(self, access_event: str, title: str, group_title, env: str, label: str, shared_run: bool, shared_run_timeout: str,
parallel, ci_build_url: str) -> dict | None:
parallel, ci_build_url: str, kind: str) -> dict | None:
request = {
"access_event": access_event,
"api_key": self.api_key,
"title": title,
"group_title": group_title,
"env": env,
"label": label,
"kind": kind,
"parallel": parallel,
"ci_build_url": ci_build_url,
"shared_run": shared_run,
Expand All @@ -151,14 +152,15 @@ def create_test_run(self, access_event: str, title: str, group_title, env: str,
log.info(f'Test run created {response.json()["uid"]}')
return response.json()

def update_test_run(self, id: str, access_event: str, title: str, group_title,
def update_test_run(self, id: str, access_event: str, title: str, group_title, kind: str,
env: str, label: str, shared_run: bool, shared_run_timeout: str, parallel, ci_build_url: str) -> dict | None:
request = {
"access_event": access_event,
"api_key": self.api_key,
"title": title,
"group_title": group_title,
"env": env,
"kind": kind,
"label": label,
"parallel": parallel,
"ci_build_url": ci_build_url,
Expand Down
5 changes: 4 additions & 1 deletion pytestomatio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def pytest_configure(config: Config):
if option == 'debug':
return

pytest.testomatio = Testomatio(TestRunConfig())
run_kind_option = config.getoption('kind')
run_kind_option = run_kind_option.lower() if run_kind_option else 'automated'

pytest.testomatio = Testomatio(TestRunConfig(run_kind_option))

url = os.environ.get('TESTOMATIO_URL') or config.getini('testomatio_url') or TESTOMATIO_URL
project = os.environ.get('TESTOMATIO')
Expand Down
5 changes: 4 additions & 1 deletion pytestomatio/testomatio/testRunConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

TESTOMATIO_TEST_RUN_LOCK_FILE = ".testomatio_test_run_id_lock"


class TestRunConfig:
def __init__(self):
def __init__(self, kind: str = 'automated'):
run_id = os.environ.get('TESTOMATIO_RUN_ID') or os.environ.get('TESTOMATIO_RUN')
title = os.environ.get('TESTOMATIO_TITLE') if os.environ.get('TESTOMATIO_TITLE') else 'test run at ' + dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
shared_run = os.environ.get('TESTOMATIO_SHARED_RUN') in ['True', 'true', '1']
Expand All @@ -17,6 +18,7 @@ def __init__(self):
self.access_event = 'publish' if os.environ.get("TESTOMATIO_PUBLISH") else None
self.test_run_id = run_id
self.title = title
self.kind = kind
self.environment = safe_string_list(os.environ.get('TESTOMATIO_ENV'))
self.exclude_skipped = exclude_skipped
self.label = safe_string_list(os.environ.get('TESTOMATIO_LABEL'))
Expand All @@ -41,6 +43,7 @@ def to_dict(self) -> dict:
result['group_title'] = self.group_title
result['env'] = self.environment
result['label'] = self.label
result['kind'] = self.kind
result['parallel'] = self.parallel
result['shared_run'] = self.shared_run
result['shared_run_timeout'] = self.shared_run_timeout
Expand Down
2 changes: 2 additions & 0 deletions pytestomatio/utils/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

RUN_KINDS = ('automated', 'manual', 'mixed')
3 changes: 3 additions & 0 deletions pytestomatio/utils/parser_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def parser_options(parser: Parser, testomatio='testomatio') -> None:
group.addoption(f'--{testomatio}',
action='store',
help=help_text)
group.addoption(f'--kind',
action='store',
help="Specify kind of test run to be created")
group.addoption(f'--testRunEnv',
action='store',
help=f'specify test run environment for testomat.io. Works only with --testomatio report')
Expand Down
8 changes: 8 additions & 0 deletions pytestomatio/utils/validations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from typing import Literal
from pytest import Config
from pytestomatio.utils.constants import RUN_KINDS
from _pytest.config.exceptions import UsageError


Expand All @@ -18,6 +19,13 @@ def validate_option(config: Config) -> Literal['sync', 'report', 'remove', 'debu
raise ValueError('Test Run id was passed. Please unset TESTOMATIO_RUN_ID or '
'TESTOMATIO_RUN env variablses to create an empty run')

run_kind_option = config.getoption('kind')
run_kind_option = run_kind_option.lower() if run_kind_option else None
if run_kind_option and option != "launch":
raise ValueError("You can choose run kind only for 'launch' option")
elif run_kind_option and run_kind_option not in RUN_KINDS:
raise ValueError(f"Not supported run kind. Choose one of next kinds: {RUN_KINDS}")

xdist_plugin = config.pluginmanager.getplugin('xdist')
if xdist_plugin and option in ('sync', 'debug', 'remove'):
if config.option.numprocesses == 0:
Expand Down
8 changes: 7 additions & 1 deletion tests/test_connect/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def test_create_test_run_success(self, mock_post, connector):
access_event="publish",
group_title="Group 1",
env="linux,chrome",
kind="automated",
label="smoke",
shared_run=False,
shared_run_timeout="2",
Expand All @@ -158,6 +159,7 @@ def test_create_test_run_success(self, mock_post, connector):
"title": "Test Run",
"group_title": "Group 1",
"env": "linux,chrome",
"kind": "automated",
"label": "smoke",
"shared_run": False,
"shared_run_timeout": "2",
Expand All @@ -181,6 +183,7 @@ def test_create_test_run_filters_none_values(self, mock_post, connector):
access_event=None,
group_title=None,
env=None,
kind="automated",
label="smoke",
shared_run=False,
shared_run_timeout=None,
Expand All @@ -192,6 +195,7 @@ def test_create_test_run_filters_none_values(self, mock_post, connector):
expected_payload = {
"api_key": "test_api_key_123",
"title": "Test Run",
"kind": "automated",
"label": "smoke",
"shared_run": False,
"parallel": True
Expand All @@ -203,7 +207,7 @@ def test_create_test_run_http_error(self, mock_post, connector):
"""Test HTTP error handled wher create test run"""
mock_post.side_effect = HTTPError("HTTP Error")

result = connector.create_test_run("Test", None, None, None, None, False, True, None, None)
result = connector.create_test_run("Test", None, None, None, None, False, True, None, None, "automated")
assert result is None

@patch('requests.Session.put')
Expand All @@ -220,6 +224,7 @@ def test_update_test_run_success(self, mock_put, connector):
title="Updated Run",
group_title="Group",
env="windows",
kind="automated",
label="regression",
shared_run=True,
shared_run_timeout='2',
Expand All @@ -235,6 +240,7 @@ def test_update_test_run_success(self, mock_put, connector):
"title": "Updated Run",
"group_title": "Group",
"env": "windows",
"kind": "automated",
"label": "regression",
"shared_run": True,
"shared_run_timeout": '2',
Expand Down
25 changes: 22 additions & 3 deletions tests/test_testomatio/test_testRunConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import patch, mock_open

from pytestomatio.testomatio.testRunConfig import TestRunConfig, TESTOMATIO_TEST_RUN_LOCK_FILE
from pytestomatio.utils.constants import RUN_KINDS


class TestTestRunConfig:
Expand All @@ -20,6 +21,7 @@ def test_init_default_values(self):
assert config.test_run_id is None
assert config.title == "test run at 2024-01-15 10:30:45"
assert config.environment is None
assert config.kind == 'automated'
assert config.exclude_skipped is False
assert config.label is None
assert config.group_title is None
Expand Down Expand Up @@ -58,6 +60,12 @@ def test_init_with_env_variables(self):
assert config.update_code is True
assert config.meta == {'linux': None, 'browser': 'chrome', '1920x1080': None}

@pytest.mark.parametrize("run_kind", RUN_KINDS)
def test_init_with_kind_passed(self, run_kind):
config = TestRunConfig(run_kind)

assert config.kind == run_kind

@pytest.mark.parametrize('value', ['True', 'true', '1'])
def test_init_shared_run_true_variations(self, value):
"""Test different true values for TESTOMATIO_SHARED_RUN"""
Expand Down Expand Up @@ -110,8 +118,9 @@ def test_init_exclude_skipped_false_variations(self, value):

assert config.exclude_skipped is False

def test_to_dict_full_data(self):
"""Test to_dict with full data"""
@pytest.mark.parametrize("run_kind", RUN_KINDS)
def test_to_dict_full_data(self, run_kind):
"""Test to_dict with full data and different run kinds"""
env_vars = {
'TESTOMATIO_RUN_ID': 'run_123',
'TESTOMATIO_TITLE': 'Test Run',
Expand All @@ -124,7 +133,7 @@ def test_to_dict_full_data(self):
}

with patch.dict(os.environ, env_vars, clear=True):
config = TestRunConfig()
config = TestRunConfig(kind=run_kind)

result = config.to_dict()

Expand All @@ -134,6 +143,7 @@ def test_to_dict_full_data(self):
'title': 'Test Run',
'group_title': 'Group 1',
'env': 'env1,env2',
'kind': run_kind,
'label': 'label1,label2',
'parallel': False,
'shared_run': True,
Expand All @@ -153,6 +163,15 @@ def test_to_dict_without_run_id(self):
assert 'id' not in result
assert result['title'] == 'No ID Run'

def test_to_dict_without_specifying_run_kind(self):
"""Test to_dict without run kind passed"""
with patch.dict(os.environ, {}, clear=True):
config = TestRunConfig()

result = config.to_dict()

assert result['kind'] == 'automated'

def test_set_env(self):
"""Test set_env"""
config = TestRunConfig()
Expand Down
14 changes: 13 additions & 1 deletion tests/test_utils/test_parser_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def test_parser_options_adds_main_testomatio_option(self, mock_parser):
help=help_text
)

def test_parser_options_adds_kind_option(self, mock_parser):
"""Test --kind option is added"""
mock_group = mock_parser.getgroup.return_value

parser_options(mock_parser)

mock_group.addoption.assert_any_call(
'--kind',
action='store',
help="Specify kind of test run to be created"
)

def test_parser_options_adds_test_run_env_option(self, mock_parser):
"""Test --testRunEnv option is added"""
mock_group = mock_parser.getgroup.return_value
Expand Down Expand Up @@ -189,7 +201,7 @@ def test_parser_options_call_count(self, mock_parser):

parser_options(mock_parser)

assert mock_group.addoption.call_count == 8
assert mock_group.addoption.call_count == 9
assert mock_parser.addini.call_count == 1


Expand Down
Loading
Loading