Behave
pip install tracera-behave
Requires Python ≥ 3.11 and Behave ≥ 1.2.6 (see Autotest adapters). tracera-behave on PyPI.
Wire the hooks in your Behave environment.py (usually under features/):
from tracera_behave.environment import (
after_all,
after_scenario,
after_step,
before_all,
before_scenario,
before_step,
)
That import is enough — Behave loads the hooks from environment.py.
Run: behave features.
Environment variables and run mode: Autotest adapters.
Bind testCaseId and autotestName
Prefer tags on the Scenario. Imperative tracera.test_case is also available from step code.
@tracera.id:42
@tracera.name:e2e/login
Scenario: Login
Given I open the login page
If @tracera.name is omitted, autotestName takes the value of the Scenario name.
Skip
Use stock Behave skip (context.scenario.skip(reason)). The skip reason is added to the result as comment.
from behave import when
@when("env is not ready")
def not_ready(context):
context.scenario.skip("env not ready — https://example.com/skip")
Steps
Each Gherkin step is recorded under the result’s Test section (title = step name, without the Given/When/Then keyword). Nest with tracera.step(title, body), @tracera.step("…"), or with / async with tracera.step("…")::
from behave import when
from tracera_behave import tracera
@when("I add to cart")
def add_to_cart(context):
with tracera.step("nested leaf"):
pass
tracera.step in before_scenario goes to the result’s Setup; Gherkin steps go to Test; tracera.step in after_scenario goes to the result’s Teardown. Suite-level hooks such as before_all / before_feature are not reported.
Comments, errors, and attachments
Comments, errors, and attachments: Autotest adapters.
from behave import when
from tracera_behave import tracera
@when("I open the login page")
def open_login(context):
tracera.comment("landed on login")
tracera.attachment(
file_name="suite-log.txt",
mime_type="text/plain",
data=b"finished login flow",
)
@when("I note the result")
def note_result(context):
tracera.comment("result-level note")
tracera.error("result-level error text")
Parameterized tests
Add @tracera.id (optional @tracera.name) to the Scenario Outline (not on each Examples row). Every row runs as its own result, all bound to that same case:
If @tracera.name is omitted, each test’s autotestName takes the value of the Scenario name after <…> is filled from its Examples row. Keep tags fixed; put varying text in the Outline title with <…>.
@tracera.id:42
@tracera.name:e2e/login
Scenario Outline: Login row
Given I open "<path>"
Examples:
| path |
| /login |
| /login/sso |
Here both /login and /login/sso report to case 42.
If each row must bind to a different case, put the id in the table and call tracera.test_case from a step:
Scenario Outline: Login row
Given I bind case <case_id> as "<name>"
And I open "<path>"
Examples:
| case_id | name | path |
| 42 | e2e/login-ok | /login |
| 43 | e2e/login-sso | /login/sso |
from behave import given
from tracera_behave import tracera
@given('I bind case {case_id:d} as "{name}"')
def bind_case(context, case_id, name):
tracera.test_case(case_id, name)