Bug: Non-8-char @id tags silently replaced on every pytest run
Version: 3.3.20260419
What happens
If an @id tag in a .feature file has any length other than exactly 8 hex chars, pytest-beehave prepends a new randomly-generated @id above the Example: line on every pytest invocation. The original tag is left as dead text. The mutation happens in pytest_configure, before collection, so there is no way to observe or prevent it without -p no:beehave.
Minimal reproduction
.feature file before running pytest:
Feature: Repro
Rule: Demo
As a user I want X So that Y
@id:abcdef012
Example: Something happens
Given a context
When an action occurs
Then an outcome is observed
After running pytest, the file becomes:
@id:abcdef012
@id:3f9a1c72
Example: Something happens
On the next run the new 8-char tag is found first, so the original tag is left as permanent dead text.
Root cause
id_generator._id_tag_precedes uses:
_ID_TAG_RE = re.compile(r"@id:[a-f0-9]{8}")
Any tag whose hex part is not exactly 8 chars does not match, so the guard that prevents double-tagging never fires.
_collect_existing_ids uses the same regex, so the non-8-char tag is also excluded from the uniqueness check — creating a window where the newly generated ID could share its first 8 chars with the original tag.
Expected behaviour
Any @id: tag, regardless of length, should be treated as already tagged and suppress new ID insertion. Ideally a validation error should be raised for malformed IDs rather than silently rewriting the file.
Workaround
Pass -p no:beehave to suppress all file mutations during development.
Bug: Non-8-char @id tags silently replaced on every pytest run
Version: 3.3.20260419
What happens
If an @id tag in a .feature file has any length other than exactly 8 hex chars, pytest-beehave prepends a new randomly-generated @id above the Example: line on every pytest invocation. The original tag is left as dead text. The mutation happens in pytest_configure, before collection, so there is no way to observe or prevent it without -p no:beehave.
Minimal reproduction
.feature file before running pytest:
Root cause
id_generator._id_tag_precedes uses:
_ID_TAG_RE = re.compile(r"@id:[a-f0-9]{8}")
Any tag whose hex part is not exactly 8 chars does not match, so the guard that prevents double-tagging never fires.
_collect_existing_ids uses the same regex, so the non-8-char tag is also excluded from the uniqueness check — creating a window where the newly generated ID could share its first 8 chars with the original tag.
Expected behaviour
Any @id: tag, regardless of length, should be treated as already tagged and suppress new ID insertion. Ideally a validation error should be raised for malformed IDs rather than silently rewriting the file.
Workaround
Pass -p no:beehave to suppress all file mutations during development.