AequilibraE / aequilibrae

aequilibrae - Python package for transportation modeling
https://www.aequilibrae.com
Other
171 stars 39 forks source link

[Suggestion] use pytest style tests (w/ fixtures etc) #326

Open elfjes opened 2 years ago

elfjes commented 2 years ago

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:

Would 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).

pedrocamargo commented 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:

pedrocamargo commented 2 years ago

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

elfjes commented 2 years ago

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:

the 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:

pedrocamargo commented 2 years ago

@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/