Introduce @env_spec for declarative test environments#250
Conversation
|
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
||
| 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| spec = {} | ||
|
|
||
| if module is not None: | ||
| m = getattr(module, 'ENV_SPEC', None) |
There was a problem hiding this comment.
Is this internal? When do we expect to have it?
There was a problem hiding this comment.
It was a mechanism to define a module-level default for tests, but it's probably unnecessary. Removed it.
| 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) |
There was a problem hiding this comment.
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
888a59b to
54fbda2
Compare
54fbda2 to
bf6ab05
Compare
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