Convert some `unittest` tests to `pytest` style
See original GitHub issueSome of our tests follow the unittest
structure of creating tests. While these are fine, we want to migrate our tests to be in the more functional style of pytest
.
For example, test_classification
which tests the classification pipeline adopts the unittest
style of class structured tests in which you must understand the whole setup to often understand one test.
In contrast, a more functional pytest
looks like test_estimators.py::test_fit_performs_dataset_compression
. Here we can define the test entirely through parameters, specify multiple parameter combinations, document which ones we expect to fail and give a reason for it. Because the test is completely defined through parameters, we can document each parameter and make the test almost completely-transparent by just looking at that one test.
We would appreciate any contributors on this side who want to get more familiar or are already familiar with testing. Some familiarity or willingness to learn pytest
’s @parametrize
and @fixture
features is a must. Please see the contribution guide if you’d like to get started!
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (6 by maintainers)
Hi @shantam-8,
So I took at
test_metrics
and I have a few pointers.Anywhere we use something like
_ProbaScorer(...)
, we should instead use the public API way of making aScorer
, i.e.make_scorer(...)
. This to ensure the public API works as intended. https://github.com/automl/auto-sklearn/blob/ee0916ece79fd8f27059c37acf08b695e2c81ac8/autosklearn/metrics/__init__.py#L242-L253It would be nice to have a docstring below each test saying what it tests:
Please feel free to make any other changes that make sense in your judgement, as long as the core thing being tested is still being tested! You should also check out the
CONTRIBUTING.md
, especially the section on testing to understand how you can run only the tests you care about. Usingpytest test/test_metric
should be enough but there’s more info in the guide if you need.You can continue asking things here or make an initial PR and we can discuss further there at any point!
Thanks for thinking to contribute 😃
Best, Eddie
Really thanks a lot for your help! I shall open a PR asap.