Open elfjes opened 2 years ago
This sounds like a good idea for the long term, but I have no extensive experience with more sophisticated use of testing frameworks. We would need to things to get started:
One thing to note is that we will soon start working on Public Transport assignment (and its corresponding file/database structure, https://github.com/AequilibraE/aequilibrae/issues/305), so that could be a good place to begin from scratch if you are willing/able to review some of those PRs to see how is the testing system being used
as a proof of concept/value I have add some pytest-style tests to #327. It makes use of fixtures to setup/teardown tests. Short summary of what is a fixture:
@pytest.fixture
), that can be given to a test function as an argumentfunction
(the default) and session
. function
scope fixtures are run before (and torn down after) each test, while session
scope fixture are only run once per test sessionconftest.py
file next to the test moduleconftest.py
filesthe MR also makes use of the builtin fixture tmp_path_factory
which is a factory fixture for creating an isolated temporary directory
If it's premature I can revert those tests back to unittest (but I like working with pytest much more, so I thought I'd just give it a go ;) )
As for test guidelines, I'm not quite sure what would be required in those guidelines. I can think of a few things though:
conftest.py
for fixtures that are required my multiple modules. I've worked (and am working) in projects that have different conftest.py
files at different levels/directories, which (while good for logical grouping) can make it very confusing to lookup/find a particular fixture.@elfjes , as you guys have been doing quite a bit of work on AequilibraE, you should be aware of this: https://www.linkedin.com/feed/update/urn:li:activity:6978111166732525568/
Aequilibrae currently uses pytest as a test runner, but does not make use of any of the (very useful) features of this package, such as fixtures and the assert (rewriting) system, since all tests are still in
unittest
style. I can see the following benefits of migrating to pytest style testing:assert something
instead ofself.assert*
is an (arbritrarily) nicer apiWould you be willing to migrate to using pytest proper? If so, what would be the prefered way of implementation? My suggestion would be
In my experience, converting from unittest to pytest can be relatively time consuming, especially if you want to do it correctly with differently scoped fixtures (but the resulting code is much more maintainable and extensible).