Conversation
| Given a set of relation alerts from two apps | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Remove |
There was a problem hiding this comment.
Should remove, patch be covered in separate feature files?
There was a problem hiding this comment.
Yes. Not just that, but I think now that we've decided to do away with add, we can have three feature files: one for each of patch, remove, and remove+patch`.
| # --------------------------------------------------------------------------- | ||
|
|
||
| Scenario: Remove an alert by name | ||
| When I apply a customization that removes alert "LowThroughput" |
There was a problem hiding this comment.
- This seems to suggest that the feature file isn't self-contained - there's a implicit dependency on some python code to make "LowThroughput" available. Not sure, but seems like an antipattern. Should we try to make the feature file more self contained? E.g. using the docstring fixture.
- I think there is room for making greater use of
parsers.parse().
There was a problem hiding this comment.
- You're right in that the feature file isn't fully self-contained. However, this seems like (more or less) normal BDD behaviour? In the case of alerts, passing them as docstrings to the set up functions would make the feature file very verbose and it would considerably decrease readability.
- Yes, let's use
parsers.parse().
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_alerts(): |
There was a problem hiding this comment.
Why not inline this (and others) in the feature file's docstring?
https://pytest-bdd.readthedocs.io/en/latest/#scenario-outlines
There was a problem hiding this comment.
This was the original unit testing added. Since we've revamped the testing to rely on Gherkin, we can scrap it.
| @given(parsers.parse('the sample alerts from "{filename}"')) | ||
| def given_sample_alerts_from_file(ctx, filename): | ||
| path = _HERE / filename | ||
| with open(path) as f: | ||
| ctx["alerts"] = yaml.safe_load(f) | ||
| ctx["original"] = copy.deepcopy(ctx["alerts"]) |
There was a problem hiding this comment.
Use a target fixture, look at https://pytest-bdd.readthedocs.io/en/latest/
Issue
Implements the unit tests in #205 using feature files.
Solution
Dependencies: Added
pytest-bddto dev dependencies to enable Gherkin feature files as the test driver.Feature Files: Created
tests/features/alert_rule_customization.featurecontaining 20 behavioral scenarios:Removal target rules: By alert name, group name, label, annotation, and topology label.
Patch updates:** For duration, alert name, expr, labels, and annotations.
Rule management: Adding rules under the fixed key.
Core properties: Input immutability, operation ordering, and instance reusability.
BDD Tests: Added
tests/test_rules_customization.pyto bindpytest-bddstep definitions to the feature file, replacing the legacy all-in-one test module.Schema Tests: Added
tests/test_rules_customization_schema.py(extracted from the old module) to isolate schema validation and no-op config tests, keeping complex bad-input matrices in cleanunittestcases.Shared Fixtures: Added
tests/conftest.pycontaining thesample_alertsfixture andfind_rulehelper function for use across test suites.Checklist
project.versionfield in thepyproject.tomlfile.Context
Testing Instructions
Upgrade Notes