automl / auto-sklearn

Automated Machine Learning with scikit-learn
https://automl.github.io/auto-sklearn
BSD 3-Clause "New" or "Revised" License
7.66k stars 1.28k forks source link

Convert some `unittest` tests to `pytest` style #1351

Open eddiebergman opened 2 years ago

eddiebergman commented 2 years ago

Some 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!

himanshu007-creator commented 2 years ago

hey, i would like to work on this issue

eddiebergman commented 2 years ago

Hey @himanshu007-creator, that'd be great!

If you have some experience with auto-sklearn or sklearn and want to have a go at trying to convert some of the pipeline components as mentioned in the Issue then that'd be amazing. If you're a bit less familiar with machine learning, we would also appreciate these changes in test/test_metrics.

However, feel free to pick whatever you think is most interesting to you and I'd be happy to provide some guidance. I will give a rough overview of what's the issues are for each major folder in tests.

himanshu007-creator commented 2 years ago

I would like to go ahead with test_metrics

shantam-8 commented 2 years ago

Hello @eddiebergman, if it is okay with @himanshu007-creator, is it possible if I could start with test_metric? It is my first time contributing to this repo and test_metric just seems to be something that I can start with.

eddiebergman commented 2 years ago

@shantam-8 Please go for it!

I will provide some guidance for it in a few hours :)

Best, Eddie

eddiebergman commented 2 years ago

Sorry I will reply tomorrow morning, some stuff came up!

eddiebergman commented 2 years ago

Hi @shantam-8,

So I took at test_metrics and I have a few pointers.

class TestScorer(unittest.TestCase):

def one(self):
    ...

To

def test_one() -> None: ...


* You can use the following replacements:
```python
# From
self.assertAlmostEqual(a, b)
self.assertTrue(t)

# To
from pytest import approx
assert a == approx(b)
assert t is True

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. Using pytest 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

shantam-8 commented 2 years ago

Really thanks a lot for your help! I shall open a PR asap.

Shubham-M-Rathod commented 7 months ago

Hello @eddiebergman It is my first time with open source and I would like to try my hands on test_evaluation, if this issue is still open.

mhaoda commented 1 month ago

Any help need on this issue?

bencondemi commented 1 week ago

Hi, can I work on this issue? Thanks!