Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[flake8]
ignore = E203, W503
max-line-length = 119
exclude = .git,venv,env,.venv,.venv38,.venv310
24 changes: 12 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ on:
env:
VERSION_FILE: setup.py
VERSION_EXTRACT_PATTERN: >-
__version__\s*=\s*'([^']+)
__version__\s*=\s*"([^"]+)
VERSION_REPLACE_PATTERN: >-
__version__ = '\1'
__version__ = "\1"
TMP_SUFFIX: _updated
CHANGE_LOG_FILE: CHANGELOG.md

Expand All @@ -25,10 +25,17 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Generate versions
uses: HardNorth/github-version-generate@v1
with:
version-source: file
version-file: ${{ env.VERSION_FILE }}
version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.10'

- name: Install dependencies
run: python -m pip install --upgrade pip setuptools wheel
Expand All @@ -42,13 +49,6 @@ jobs:
user: ${{ secrets.PYPI_USERNAME }}
password: ${{ secrets.PYPI_PASSWORD }}

- name: Generate versions
uses: HardNorth/github-version-generate@v1
with:
version-source: file
version-file: ${{ env.VERSION_FILE }}
version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }}

- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2-latest
with:
Expand Down Expand Up @@ -106,8 +106,8 @@ jobs:
- name: Update version file
id: versionFileUpdate
run: |
export CURRENT_VERSION_VALUE=`echo '${{ env.CURRENT_VERSION }}' | sed -E "s/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/"`
export NEXT_VERSION_VALUE=`echo '${{ env.NEXT_VERSION }}' | sed -E "s/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/"`
export CURRENT_VERSION_VALUE=`echo '${{ env.CURRENT_VERSION }}' | sed -E 's/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/'`
export NEXT_VERSION_VALUE=`echo '${{ env.NEXT_VERSION }}' | sed -E 's/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/'`
sed "s/${CURRENT_VERSION_VALUE}/${NEXT_VERSION_VALUE}/g" ${{ env.VERSION_FILE }} > ${{ env.VERSION_FILE }}${{ env.TMP_SUFFIX }}
rm ${{ env.VERSION_FILE }}
mv ${{ env.VERSION_FILE }}${{ env.TMP_SUFFIX }} ${{ env.VERSION_FILE }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11', '3.12' ]
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13' ]

steps:
- name: Checkout repository
Expand All @@ -27,7 +27,7 @@ jobs:
run: tox

- name: Upload coverage to Codecov
if: matrix.python-version == 3.8 && success()
if: matrix.python-version == 3.10 && success()
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ celerybeat.pid
.venv
env/
venv/
.venv3*/
ENV/
env.bak/
venv.bak/
Expand Down
43 changes: 24 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.0.0
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
- id: pydocstyle
exclude: |
(?x)^(
tests/.* |
examples/.*
)
- repo: https://github.com/Lucas-C/pre-commit-hooks-markup
rev: v1.0.1
(?x)^(
tests/.* |
examples/.*
)
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
args: [ '--check' ]
- repo: https://github.com/pycqa/isort
rev: 6.0.0
hooks:
- id: rst-linter
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
- id: flake8
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [Unreleased]
### Added
- Support for `Python 3.13`, by @HardNorth
### Changed
- Client version updated to [5.6.5](https://github.com/reportportal/client-Python/releases/tag/5.6.5), by @HardNorth
- Behave version updated to [1.3.3](https://github.com/behave/behave/releases/tag/v1.3.3), by @HardNorth
### Removed
- `Python 3.7` support, by @HardNorth

## [4.0.3]
### Added
- Python 12 support, by @HardNorth

## [4.0.2]
Expand Down
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
include MANIFEST.in
include README.rst requirements.txt
include LICENSE README.md CHANGELOG.md requirements.txt
189 changes: 189 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# agent-python-behave

[![PyPI version](https://img.shields.io/pypi/v/behave-reportportal.svg)](https://pypi.python.org/pypi/behave-reportportal)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/behave-reportportal.svg)](https://pypi.org/project/behave-reportportal)
[![CI](https://github.com/reportportal/agent-python-behave/actions/workflows/tests.yml/badge.svg)](https://github.com/reportportal/agent-python-behave)
[![codecov](https://codecov.io/gh/reportportal/agent-python-behave/branch/master/graph/badge.svg)](https://codecov.io/gh/reportportal/agent-python-behave)
[![Join Slack chat!](https://img.shields.io/badge/slack-join-brightgreen.svg)](https://slack.epmrpp.reportportal.io/)
[![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal)

Behave extension for reporting test results of Behave to the ReportPortal.

- **Usage**
- **Installation**
- **Configuration**
- **Launching**
- **Test item attributes**
- **Logging**
- **Test case ID**
- **Integration with GA**
- **Copyright Notice**

## Usage

### Installation

To install agent-python-behave run:

```bash
pip install behave-reportportal
```

You can find an example of integration with behave
agent [here](https://github.com/reportportal/agent-python-behave/blob/master/tests/features/environment.py).
You can just copy this file to your features folder.

## Configuration

Prepare the config file `behave.ini` in the root directory of tests or specify
any one using behave command line option:

```bash
behave -D config_file=<path_to_config_file>
```

The `behave.ini` file should have the following mandatory fields under `[report_portal]` section:

- `api_key` - value can be found in the User Profile section
- `project` - name of project in ReportPortal
- `endpoint` - address of ReportPortal Server

Example of `behave.ini`:

```text
[report_portal]
api_key = fb586627-32be-47dd-93c1-678873458a5f
endpoint = http://192.168.1.10:8080
project = user_personal
launch_name = AnyLaunchName
launch_attributes = Slow Smoke
launch_description = Smoke test
```

The following parameters are optional:

- `client_type = SYNC` - Type of the under-the-hood ReportPortal client implementation. Possible
values: [SYNC, ASYNC_THREAD, ASYNC_BATCHED].
- `launch_name = AnyLaunchName` - launch name (default value is 'Python Behave Launch')
- `launch_id = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` - id of the existing launch (the session will not handle the
lifecycle of the given launch)
- `launch_attributes = Smoke Env:Python3` - list of attributes for launch
- `launch_description = Smoke test` - launch description
- `debug_mode = True` - creates the launch either as debug or default mode (defaults to False)
- `log_layout = Nested` - responsible for Scenario, Step or Nested based logging (Scenario based approach is used by
default)
- `is_skipped_an_issue = False` - option to mark skipped tests as not 'To Investigate' items on Server side.
- `retries = 3` - amount of retries for performing REST calls to RP server
- `rerun = True` - marks the launch as the rerun
- `rerun_of = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` - launch id to rerun
- `launch_uuid_print = True` - Enables printing Launch UUID on test run start. Default `False`.
- `launch_uuid_print_output = stderr` - Launch UUID print output. Default `stdout`. Possible values: [stderr, stdout].
- `connect_timeout = 15` - Connection timeout to ReportPortal server. Default value is "10.0".
- `read_timeout = 15` - Response read timeout for ReportPortal connection. Default value is "10.0".
- `log_batch_size = 20` - maximum number of log entries which will be sent by the agent at once
- `log_batch_payload_size = 65000000` - maximum payload size of a log batch which will be sent by the agent at once

If you would like to override the above parameters from command line, or from CI environment based on your build, then
pass:

- `-D parameter=value` during invocation.

## Launching

To execute tests with ReportPortal run `behave` command and specify path to feature files:

```bash
behave ./tests/features
```

## Test item attributes

Tag `attribute` can be used to specify attributes for features and scenarios.
Attributes should be listed inside brackets of attribute tag separated by commas.

Example:

```python
@attribute(key:value, value2)
@attribute(some_other_attribute)
Feature: feature name

@attribute(key:value, value2, value3)
Scenario: scenario name
```

## Logging

For logging of the test item flow to ReportPortal, please, use the python
logging handler and logger class provided by extension like below.

In `environment.py`:

```python
import logging

from reportportal_client import RPLogger, RPLogHandler

from behave_reportportal.behave_agent import BehaveAgent, create_rp_service
from behave_reportportal.config import read_config


def before_all(context):
cfg = read_config(context)
context.rp_client = create_rp_service(cfg)
context.rp_client.start()
context.rp_agent = BehaveAgent(cfg, context.rp_client)
context.rp_agent.start_launch(context)
logging.setLoggerClass(RPLogger)
log = logging.getLogger(__name__)
log.setLevel("DEBUG")
rph = RPLogHandler(rp_client=context.rp_client)
log.addHandler(rph)
context.log = log
```

Logger provides ability to attach some file in scope of log message (see examples below).

In steps:

```python
@given("I want to calculate {number_a:d} and {number_b:d}")
def calculate_two_numbers(context, number_a, number_b):
context.number_a = number_a
context.number_b = number_b
context.log.info("log message")

# Message with an attachment.
import subprocess
free_memory = subprocess.check_output("free -h".split())
context.log.info(
"log message with attachment",
attachment={
"name": "free_memory.txt",
"data": free_memory,
"mime": "application/octet-stream",
},
)
```

## Test case ID

It's possible to mark some scenario with `test_case_id(<some_id>)` tag. ID specified in brackets will be sent to
ReportPortal.

## Integration with GA

ReportPortal is now supporting integrations with more than 15 test frameworks simultaneously. In order to define the
most popular agents and plan the team workload accordingly, we are using Google analytics.

ReportPortal collects information about agent name and its version only. This information is sent to Google analytics
on the launch start. Please help us to make our work effective. If you still want to switch Off Google analytics,
please change env variable the way below.

```bash
export AGENT_NO_ANALYTICS=1
```

## Copyright Notice

Licensed under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) license (see the LICENSE file).
Loading