Skip to content

Commit

Permalink
add jira options to ini (#44)
Browse files Browse the repository at this point in the history
* add jira options to ini

* Add systemtest

* Remove unused imports

* fix jira strings test

* remove autoload

* Fix system test

* fix system test

* Combine unittests

* fix black

* Add changelog

Co-authored-by: Guido Schmitz <guido.schmitz@fedaix.de>
  • Loading branch information
Markus Bong and Shutgun authored Jun 7, 2022
1 parent 85bb70a commit 900b145
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.7.2] - 2022/06/07

### Fixed

* Jira settings are also properly defined to avoid warnings

## [5.7.1] - 2022/06/07

### Fixed
Expand Down
4 changes: 4 additions & 0 deletions pytest_adaptavist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def add_option_ini(
parser.addini("test_case_order", help="Specify test case order.")
parser.addini("test_case_range", help="Specify test case range.")

parser.addini("jira_server", help="Specify your jira server.")
parser.addini("jira_username", help="Specify your jira username.")
parser.addini("jira_password", help="Specify your jira password.")


@pytest.hookimpl(trylast=True)
def pytest_configure(config: Config):
Expand Down
80 changes: 71 additions & 9 deletions tests/test_ini.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"""Test pytest.ini configuration."""
import os

import pytest
from adaptavist import Adaptavist

from pytest_adaptavist import PytestAdaptavist
from tests import get_test_values, read_global_config, system_test_preconditions


@pytest.mark.usefixtures("adaptavist_mock")
class TestIniConfig:
class TestIniConfigUnit:
"""Test pytest.ini configuration on unit test level."""

@pytest.mark.parametrize(
Expand All @@ -27,10 +33,10 @@ def test_ini_config_strings(self, pytester: pytest.Pytester, monkeypatch: pytest
monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1")
pytester.makepyfile(
"""
def test_T1(meta_block):
with meta_block(1) as mb_1:
mb_1.check(True)
"""
def test_T1(meta_block):
with meta_block(1) as mb_1:
mb_1.check(True)
"""
)
pytester.makeini(
f"""
Expand All @@ -40,17 +46,73 @@ def test_T1(meta_block):
)

report = pytester.inline_run("--adaptavist", plugins=["adaptavist", "assume"])
assert getattr(report._pluginmanager.get_plugin("_adaptavist"), option) in (
assert getattr(report._pluginmanager.get_plugin("_adaptavist"), option) in ( # pylint: disable=protected-access
"C1",
["C1"],
) # pylint: disable=protected-access
)

result = pytester.runpytest("--adaptavist", plugins=["adaptavist", "assume"])
assert "warnings" not in result.parseoutcomes()

monkeypatch.setenv(option, "C2")
report = pytester.inline_run("--adaptavist", plugins=["adaptavist", "assume"])
assert getattr(report._pluginmanager.get_plugin("_adaptavist"), option) in (
assert getattr(report._pluginmanager.get_plugin("_adaptavist"), option) in ( # pylint: disable=protected-access
"C2",
["C2"],
) # pylint: disable=protected-access
)

def test_jira_settings(self, pytester: pytest.Pytester):
"""Test that jira settings in pytest.ini are correctly used and recognized by pytest."""
pytester.makepyfile(
"""
def test_T1(meta_block):
with meta_block(1) as mb_1:
mb_1.check(True)
"""
)
pytester.makeini(
"""
[pytest]
jira_server = https://jira.test
jira_username = username
jira_password = password
"""
)
report = pytester.inline_run("--adaptavist", plugins=["adaptavist", "assume"])
adaptavist: PytestAdaptavist = report._pluginmanager.get_plugin("_adaptavist") # pylint: disable=protected-access
assert adaptavist.adaptavist.jira_server == "https://jira.test"
assert adaptavist.adaptavist._authentication.username == "username" # pylint: disable=protected-access
assert adaptavist.adaptavist._authentication.password == "password" # pylint: disable=protected-access


@pytest.mark.system
@pytest.mark.skipif(not system_test_preconditions(), reason="Preconditions for system tests not met. Please see README.md")
class TestIniConfigSystem:
"""Test pytest.ini configuration on system test level."""

def test_T1(self, pytester: pytest.Pytester, adaptavist: Adaptavist):
"""Test passing a test."""
pytester.makepyfile(
"""
def test_T1(meta_block):
with meta_block():
with meta_block(1) as mb_1:
mb_1.check(True)
"""
)
config = read_global_config()
pytester.makeini(
f"""
[pytest]
project_key = {config["project_key"]}
jira_server = {config["jira_server"]}
jira_username = {config["jira_username"]}
jira_password = {config["jira_password"]}
"""
)
os.remove("config/global_config.json")
report = pytester.inline_run("--adaptavist")
test_run_key, test_name = get_test_values(report)
test_result = adaptavist.get_test_result(test_run_key, test_name)
assert test_result["status"] == "Pass"
assert test_result["scriptResults"][0]["status"] == "Pass"

0 comments on commit 900b145

Please sign in to comment.