Skip to content

Introduce @env_spec for declarative test environments#250

Merged
GuyAv46 merged 1 commit into
RedisLabsModules:masterfrom
LukeMathWalker:declarative-env
May 25, 2026
Merged

Introduce @env_spec for declarative test environments#250
GuyAv46 merged 1 commit into
RedisLabsModules:masterfrom
LukeMathWalker:declarative-env

Conversation

@LukeMathWalker
Copy link
Copy Markdown
Contributor

@LukeMathWalker LukeMathWalker commented May 18, 2026

A building block which, later on, can be used by the scheduling pipeline to maximise env reuse across tests in the same suite.

You can see it in action in RediSearch/RediSearch#9706

@GuyAv46 GuyAv46 self-requested a review May 18, 2026 14:53
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 18, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 53.84615% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.83%. Comparing base (02cfbb9) to head (bf6ab05).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
RLTest/__main__.py 0.00% 12 Missing ⚠️
RLTest/loader.py 0.00% 11 Missing ⚠️
RLTest/env_spec.py 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #250      +/-   ##
==========================================
+ Coverage   32.46%   34.83%   +2.37%     
==========================================
  Files          17       18       +1     
  Lines        2597     2733     +136     
==========================================
+ Hits          843      952     +109     
- Misses       1754     1781      +27     
Flag Coverage Δ
unittests 34.83% <53.84%> (+2.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@GuyAv46 GuyAv46 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

Comment thread RLTest/__main__.py Outdated

if len(test_args) > 0 and not test.is_method:
# For bound methods, drop the implicit ``self`` so we can detect a
# declared ``env`` parameter the same way for functions and methods.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the class-method change here.
We now accept tests like

class Test_my_test:
  def test_my_test(self, env):
    ...

and pass the env from the spec, if there's one? How do we pass the spec in this case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It assumed __init__ had saved env in self.env.
Removed it: now methods must pick up the env from self, which is clearer and simpler.

Comment thread RLTest/env_spec.py Outdated
spec = {}

if module is not None:
m = getattr(module, 'ENV_SPEC', None)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this internal? When do we expect to have it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a mechanism to define a module-level default for tests, but it's probably unnecessary. Removed it.

Comment thread RLTest/env_spec.py Outdated
Comment on lines +128 to +139
if owner_class is not None:
# ``@env_spec`` decoration on the class itself writes to ``_ATTR``.
c = getattr(owner_class, _ATTR, None)
if c is not None:
declared = True
spec.update(c)

if test_func is not None:
f = getattr(test_func, _ATTR, None)
if f is not None:
declared = True
spec.update(f)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only use one of them at a time, with the same logic, and since Python is not type-strict, consider unifying the API for both cases, and make this single param mandatory

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@GuyAv46 GuyAv46 merged commit 1956a9a into RedisLabsModules:master May 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants