pytest-dev / pytest-dev/pytest-bdd

How to customize auto-generated test name when using Scenario Outline?

Open
#355 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
251
Avg merge
43m
Merged PRs (30d)
2

Description

First things first, thanks to everybody involved for creating such a useful module, I'm loving it. It took some time getting used to but now I feel like I'm flying.

Now the question: How to customize auto-generated test name when using Scenario Outline?
I have a test scenario where I'm using data

compare = [<, =, >]
name = [RISING, FALLING, NONE]
seconds= [0.0, 1.0]

that forms a Examples: table:

Examples:
| compare | seconds | name   |
| <       | 0       | NONE   |
| <       | 1       | NONE   |
| =       | 0       | NONE   |
| =       | 1       | NONE   |
| >       | 0       | NONE   |
| >       | 1       | NONE   |
| =       | 0       | RISING |
...

for this

@scenario('executed.feature', 'Scenario becoming true',
          example_converters=dict(compare=str, seconds=float, name=str))
def test_scenario_never_becomes_true():
    pass

and the output looks like
image

I've tried searching for pytest hook where I could get the test and generate a new name for it but didn't manage to find anything.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the @scenario usage and executed.feature, then trace how the Scenario Outline Examples rows become pytest test names. Determine whether the project exposes a supported naming hook or configuration point. Done means a documented way to customize generated names, with coverage for the shown compare, seconds, and name values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.