Full migration to idiomatic pytest - #1225
Conversation
Move each module's SERVICE_CONFIG to module level, share the validate-and-instantiate pipeline as get_validated_service, and derive duplicated config fixtures from SERVICE_CONFIG.
Fake API payloads become record/extra fixtures returning fresh objects (a data SimpleNamespace where values are interdependent), replacing the mix of mutable class attributes and TEST_*/ARBITRARY_* constants.
Validation classes are TestXConfig, config fixtures target 'myservice', and gmail drops its bespoke section name.
Every service test module must define a module-level SERVICE_CONFIG and keep fake data in fixtures rather than mutable class attributes.
The test layered responses.activate on top of the class's autouse RequestsMock, relying on nested-mock shadowing.
test_templates kept its fake payload as class attributes and deck built services through a plain method rather than a factory fixture.
A single conftest factory reads each module's SERVICE_CLASS and SERVICE_CONFIG, replacing the per-module copies. Modules that mock at construction keep a local fixture built on the shared factory; bugzilla, azuredevops, and deck override it outright.
The SimpleNamespace bundles in the gitlab, github, jira, and redmine tests become one fixture per value, with interdependencies expressed as fixture parameters, so all modules share the record/extra fixture shape.
ryneeverett
left a comment
There was a problem hiding this comment.
- FYI, I'm thinking I'll squash merge this one. The commit structure was helpful for review but I'm not sure how helpful it would be in a
git blamescenario. I also noticed that the commits do not appear to all be atomic in the sense that the tests pass -- f825c0c removes ConfigTest which is still depended on. - Please update the tutorial.rst Tests section to reflect the new pattern.
- This is more an idea for the future than something I'd want added to this PR, but would is make sense to make
configa shared fixture across services? My thought is that is might be confusing that the default differs fromSERVICE_CONFIG. It would require some reworking in a lot of the services, but it seems nice if they all used a fixture like Trello:
@pytest.fixture
def config(self):
return {'general': {'targets': ['myservice']}, 'myservice': {**SERVICE_CONFIG}}
Agreed, I created multiple commits to avoid having a single really big diff, but we can definitely squash them before merging. Do you want me to do it now, or wait ?
Not sure I understand how you want to pass the |
test_docs.py is now 61% faster, and full test suite 45% faster
|
@ryneeverett I added a commit to speed up the documentation tests (as well as the actual doc generation). |
this package is a transitive dependency, used by ini2toml.
|
I'll squash at the end since the github UI makes it super easy, I just wanted to get your opinion. I hadn't been squashing your PR's lately since the commits have been well-structured and truly atomic.
It seems like we could use the request fixture and do something like: @pytest.fixture
def config(self, request):
return {'general': {'targets': ['myservice']}, 'myservice': {**request.module.SERVICE_CONFIG}} |
Last PR to close #1160
This PR mostly does 2 things:
Standard Pytest
This change is quite opinionated, but here is why I think it improves the code:
Service tests consistency
Each service test was defining and using its data differently, once again making it harder to add a change for all services at once, I tried to make them a bit more similar. I added a few tests to ensure basic consistency
I tried to create atomic commits to ease the review. If that's still too much, I can create multiple PRs