[TST]: Groupby raised error with duplicate column names
- [x] closes #31735 
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

Added a test to avoid regression