Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why favor class-based over function-based tests? #19

Open
bittner opened this issue Jun 28, 2023 · 1 comment
Open

Why favor class-based over function-based tests? #19

bittner opened this issue Jun 28, 2023 · 1 comment

Comments

@bittner
Copy link

bittner commented Jun 28, 2023

The test examples in the README favor class-based over function-based tests. Clearly, you're inheriting from DRF test classes and go from there.

Is this a concious choice or more of a compromise?

I prefer writing test code function-based with Pytest to reduce visual clutter, so I try to understand whether it's possible to do that with pytest-drf. If it is not, currently is it feasible to adapt the implementation in a way that it would be?

@theY4Kman
Copy link
Owner

Could you show me an example of the same test written in both class-based and function-based form? I don't think I understand the difference between the two.

Though, to be clear, pytest-drf is fixture-based, and classes are the only sensible way to package up a set of fixtures without polluting all tests in the session (as one of the fixtures is, critically, an autouse fixture). I suppose a pytest library could provide a submodule to be imported like from pytest_drf.module_scoped import *, so tests could be written at module-level – but all assertion-rewriting would be missed, so we'd have to invoke that manually ourselves, somehow.

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

No branches or pull requests

2 participants