Skip to content

Commit

Permalink
feature: execution of selected tests
Browse files Browse the repository at this point in the history
If you use the `testops` mode and specify a plan ID then the reporter will run the tests specified in the test plan based on their IDs.
  • Loading branch information
gibiw committed Aug 6, 2024
1 parent ac375ac commit fee9578
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
24 changes: 14 additions & 10 deletions qase-pytest/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

## What's new

The decorator `qase.id()` supports specifying multiple IDs.
- the decorator `qase.id()` supports specifying multiple IDs.

```python
@qase.id([2,3])
def test_example():
pass
```
```python
@qase.id([2,3])
def test_example():
pass
```

- if you use the `testops` mode and specify a plan ID then the reporter will run the tests specified in the test plan
based on their IDs.
- exclude the default parameters that are added by additional libraries and start with `__pytest`

# qase-pytest 6.1.0b3

Expand All @@ -23,10 +27,10 @@ Fixed an issue then `qase-pytest-capture-logs` parameter did not set correct val
Fixed the following issues:

- issue with `qase-pytest-capture-logs` parameter [#234].
When using the "qase-pytest-capture-logs" parameter, an error occurred:
`pytest: error: unrecognized arguments: --qase-pytest-capture-logs=true`
- issue with `qase-testops-batch-size` parameter [#235].
When using the "qase-pytest-capture-logs" parameter, an error occurred:
`pytest: error: unrecognized arguments: --qase-pytest-capture-logs=true`

- issue with `qase-testops-batch-size` parameter [#235].
When using the "qase-testops-batch-size" parameter, an error occurred:
`TypeError: '>' not supported between instances of 'str' and 'int'`

Expand Down
31 changes: 21 additions & 10 deletions qase-pytest/src/qase/pytest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
self.runtime = Runtime()
self.reporter = reporter
self.run_id = None
self.execution_plan = None
self.execution_plan = reporter.get_execution_plan()

self.reporter.setup_profilers(runtime=self.runtime)

Expand All @@ -70,9 +70,14 @@ def drop_run_id():
def pytest_collection_modifyitems(self, session, config, items):
# Filter test cases based on ids
if self.execution_plan:
items[:] = [item for item in items if
item.get_closest_marker('qase_id') and item.get_closest_marker('qase_id').kwargs.get(
"id") in self.execution_plan]
new_items = []
for item in items:
if item.get_closest_marker('qase_id'):
ids = QasePytestPlugin._get_qase_ids(item)
if any(id in self.execution_plan for id in ids):
new_items.append(item)

items[:] = new_items

def pytest_sessionstart(self, session):
if is_xdist_controller(session):
Expand Down Expand Up @@ -261,15 +266,21 @@ def _set_muted(self, item) -> None:

def _set_testops_id(self, item) -> None:
try:
ids = item.get_closest_marker("qase_id").kwargs.get("id")
if ',' in ids:
ids = [int(i) for i in re.split(r'\s*,\s*', ids)]
self.runtime.result.testops_id = ids
else:
self.runtime.result.testops_id = [int(ids)]
ids = QasePytestPlugin._get_qase_ids(item)
self.runtime.result.testops_id = ids
except:
pass

@staticmethod
def _get_qase_ids(item) -> Union[None, List[int]]:
ids = item.get_closest_marker("qase_id").kwargs.get("id")
if ids is None:
return None
if isinstance(ids, int):
return [ids]
else:
return [int(i) for i in re.split(r'\s*,\s*', ids)]

def _set_params(self, item) -> None:
if hasattr(item, 'callspec'):
for key, val in item.callspec.params.items():
Expand Down
11 changes: 7 additions & 4 deletions qase-python-commons/src/qase/commons/reporters/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ..models import Result, Attachment, Runtime
from ..models.config.qaseconfig import Mode
from typing import Union
from typing import Union, List

from ..models.result import InternalResult

Expand All @@ -23,7 +23,7 @@ def __init__(self, config: ConfigManager):
config.validate_config()
self.config = config.config
self.logger = Logger(self.config.debug)
self.execution_plan = None
self._execution_plan = None
self.profilers = []
self.overhead = 0

Expand Down Expand Up @@ -160,6 +160,9 @@ def complete_worker(self) -> None:
self.logger.log(e, 'error')
self._run_fallback()

def get_execution_plan(self) -> Union[None, List[int]]:
return self._execution_plan

def _run_fallback(self) -> None:
if self.fallback:
try:
Expand All @@ -185,8 +188,8 @@ def _load_testops_plan(self) -> None:
api_token=self.config.testops.api.token,
host=self.config.testops.api.host
)
self.execution_plan = loader.load(self.config.testops.project,
int(self.config.testops.plan.id))
self._execution_plan = loader.load(self.config.testops.project,
int(self.config.testops.plan.id))
except Exception as e:
self.logger.log('Failed to load test plan from Qase TestOps', 'info')
self.logger.log(e, 'error')
Expand Down

0 comments on commit fee9578

Please sign in to comment.