Skip to content

Introduce @env_spec for declarative test environments#250

Open
LukeMathWalker wants to merge 1 commit into
RedisLabsModules:masterfrom
LukeMathWalker:declarative-env
Open

Introduce @env_spec for declarative test environments#250
LukeMathWalker wants to merge 1 commit into
RedisLabsModules:masterfrom
LukeMathWalker:declarative-env

Conversation

@LukeMathWalker
Copy link
Copy Markdown

@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

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

Codecov Report

❌ Patch coverage is 59.45946% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.13%. Comparing base (02cfbb9) to head (888a59b).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
RLTest/__main__.py 0.00% 18 Missing ⚠️
RLTest/loader.py 0.00% 11 Missing ⚠️
RLTest/env_spec.py 97.72% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #250      +/-   ##
==========================================
+ Coverage   32.46%   35.13%   +2.67%     
==========================================
  Files          17       18       +1     
  Lines        2597     2755     +158     
==========================================
+ Hits          843      968     +125     
- Misses       1754     1787      +33     
Flag Coverage Δ
unittests 35.13% <59.45%> (+2.67%) ⬆️

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

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?

Comment thread RLTest/env_spec.py
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?

Comment thread RLTest/env_spec.py
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

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