Most of the pytest unit test code I'm looking at ends up turning into giant write-once files (revisit only if tests fail) that are impossible to navigate -- do folks know of open source projects in the Python world that do a really exemplary job organizing their tests (not just the files, but the contents of said files, and the names/object hierarchy of the tests)?
@FPinaMartins Thank you -- I certainly like the relatively small size per file. Right now I'm fighting with files like https://github.com/freedomofpress/securedrop-client/blob/main/tests/gui/test_widgets.py (admittedly the tested widgets.py reaaaally needs to be refactored).
Thanks, we tried our best to avoid having very large files, since there were 3 of us working together at one time.
That `test_widgets.py` is certainly huge! If you are going to refactor that, *maybe* you could consider segregating parts of `widgets.py` too. It might make the job of refactoring the tests easier too.
I leave answering the question of whether the efforts compensate the benefits to you. _-)
@eloquence idk if i'd call it exemplary, but i had to debug a test failure in Picard a few days ago and it was rather easy to make sense of, even though it was my first time for both just using the software and for looking at its source code.
i knew some Python, but i've never written tests in it, or knew anything about how tests are written.
they seem to be using some fancy new-ish QuickCheck-derived library too, although that wasn't used for the part i interacted with.
@eloquence *how tests are written in Python.
i did learn about TDD and stuff.
re: programming, python
@eloquence I will add that the widget tests like the name suggest is about GUI.
It is whole other story to test GUI stuff.
Ask web frontned people.
Otherwise, I do not mind large files (especially if they use mostly functions).
I prefer side-effects free functions, I test only the public interface and particular difficult implementation details.
Regarding GUI, I only do nominal tests.
In particular testing for side-effects like "click this button, receive an email" is verrrrrrrrrrrry painful.
The advantage of Declarative GUI, is that you can serialize the GUI and test using xpath or whatever whether a particular element is present or not.
The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!