TST: organize and cleanup pandas/tests/groupby/test_aggregate.py
State: closed

closes #18490

Module currently has tests in 2 classes (`TestGroupByAggregate` and `TestGroupByAggregateCython`). The remaining tests are not in a class.

Also made the following changes:

### TestGroupByAggregate class
#### test_agg_must_agg
* replaced `pytest.raises` with `tm.assert_raises_regex`

#### test_agg_apply_corner
* made it more readable

#### test_agg_multiple_functions_too_many_lambdas
* replaced `pytest.raises` with `tm.assert_raises_regex`

#### test_multi_function_flexible_mix
* made it more readable

### TestGroupByAggregateCython class

_all test methods that contain cython in the test name_

#### test_cython_agg_nothing_to_agg
* replaced `pytest.raises` with `tm.assert_raises_regex`

#### test_cython_agg_return_dict
* replaced `self.df` with df initialized inside function

### All Others

#### test_agg_dict_renaming_deprecation
* made it more readable

#### test_agg_nested_dicts
* replaced `pytest.raises` with `tm.assert_raises_regex`
* made it more readable

#### test_agg_item_by_item_raise_typeerror
* replaced `pytest.raises` with `tm.assert_raises_regex`

#### test_agg_structs_series
* made it more readable


Labels:
name: Testing
description: pandas testing functions or related to the test suite
name: Clean

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18931?src=pr&el=h1) Report
> Merging [#18931](https://codecov.io/gh/pandas-dev/pandas/pull/18931?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/84335621ad0a0d83302a80b6911d3985c00b5cee?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/18931/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/18931?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #18931      +/-   ##
==========================================
- Coverage   91.58%   91.58%   -0.01%     
==========================================
  Files         150      150              
  Lines       48972    48972              
==========================================
- Hits        44851    44849       -2     
- Misses       4121     4123       +2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.94% <ø> (-0.01%)` | :arrow_down: |
| #single | `41.72% <ø> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18931?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/18931/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `84.74% <0%> (-0.22%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18931?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18931?src=pr&el=footer). Last update [8433562...5d763ff](https://codecov.io/gh/pandas-dev/pandas/pull/18931?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks @alysivji 

can you split things out to new files?

IOW each of these classes to a separate file, something like

``pandas/tests/groupby/aggregate/test_cython`` (2nd one)
``test_aggregate`` (1st class)
``test_other`` (3rd one)

just to make this even more organized.

be sure to add a ``__init__.py`` in the sub-dir
* Split up the files
* cleaned up the imports
* changed all assert_frame/assert_series calls to `tm.assert_*`
* more cleaning up tests to increase readability
* rebased

@jreback lemme know if anything else needs to be done.

Thanks!
cc @TomAugspurger I think we have to merge #18921 (when ready) before this (and rebase this on master)?
Yes it'd be nice to merge #18921 before this. Backporting can be tricky when files are split.
@alysivji but go ahead and make the changes as above when you can. we will be merging @TomAugspurger soon anyhow.
@jreback Changes have been made. Also deleted the cython test class, not needed anymore since it's in a separate module.

I can rebase when @TomAugspurger 's changes get in.

Also started working on turning the `test_aggregate.py` setup into fixtures. Lots of moving pieces for one PR; will send a separate request once this is merged.
@alysivji if you want to rebase we can get this in.
@jreback all green!

Will start working on refactoring the setup method to fixtures this weekend.
thanks @alysivji 

would like to remove the imports *inside* functions as well (and consolidate at the top-level) on your next PR.