3 ms·
Call me crazy, but I go even more verbose than that. I go full Rspec/BDD mode: class TestAuthenticateMethod: class TestWhenUserExists:
by herpderperator 6y ago
Call me crazy, but I go even more verbose than that. I go full Rspec/BDD mode:
class TestAuthenticateMethod:
class TestWhenUserExists:
class TestWhenPasswordIsValid:
def test_it_returns_200(self, app, user):
assert ...
class TestWhenPasswordIsInvalid:
def test_it_returns_403(self, app, user):
assert ...
class TestWhenUserDoesNotExist:
def test_it_returns_403(self, app, user):
assert ...
It is so worth it. I can look back at my tests 3 months later and know exactly what was intended wthout duplicating explanations with comments. Yes some methods can get a bit long and indented, but it's worth it for me. The other downside is you have to start all classes/methods with "test" but I got used to that very quickly.
When you run pytest it's very clear what's being tested and what the expected outcome is since it gives you the full class hierarchy in the output.
- mumblemumble 6y agoThis idea is both crazy and genius. Thanks for sharing.
- jkaptur 6y agoI’ve been working on a codebase like this, and my major complaint is that I’ll see a deeply-nested test and have to scroll waaaaay up to understand the context. I prefer ‘foo_bar_baz’, ‘foo_bar_qux’ to foo <snip 1000 lines> bar <snip 553 lines> baz <snip 243 lines> qux
- BerislavLopac 6y agoThis is neat, but pytest allows for similar granulation using the right fixtures: E.g. in test_authenticate_method.py: def test_returns_200_on_valid_password(app, user_exists): ... def test_returns_403_on_valid_password(app, user_exists): ... def test_returns_403(app, user_not_exist): ...