Despite what the name implies, TestBaseUserSerializer is not just a base class: it's an actual TestCase. It's defined in accounts.tests.test_serializers and run there, but also accidentally run a second time in addons.tests.test_serializers which imports it.
We need to re-organize the tests to avoid this.
@diox Can't we define the TestBaseUserSerializer TestCase in the addons.tests.test_serializers to avoid running it two times.
No, accounts.tests.test_serializers is the right place for that class. The simplest approach with no code re-organization is probably to import it under a different name in addons.tests.test_serializers so that it's not picked up by pytest, or refactor the class to have a re-usable mixin that contains all the base tests and import that instead of the actual testcase class.
Thank You ! Can you give an alias to TestBaseUserSerializer , so I can land a PR on it .
Any name that is close enough to the original but do not cause pytest to collect the class as a test class would work for me. I'd try importing as either BaseTestUserSerializer or _TestBaseUserSerializer (avoiding the Test prefix).
Test if that works by importing as the new name in addons.tests.test_serializers and then running pytest on that file - you'll know you succeeded if pytest doesn't collect the test class.
Giving an alias to TestBaseUserSerializer in addons.tests.test_serializers does not worked , It still collects the test class from accounts.tests.test_serializers. Even just importing the TestBaseUserSerializer will again run it, we will need another solution.
Not sure I follow. Collecting the test class from accounts.tests.test_serializers is fine, it's collecting it a second time from its aliased name in addons.tests.test_serializers that is not.
Yes, but on running pytest on addons.tests.test_serializers with alias BaseTestUserSerializer, it still collects the TestCase from the parent file. So what should be the next step to avoid it ?
More investigation is needed - there are multiple ways to do this, but I don't have too much time to support such a minor issue, so if you can't figure it yourself, please pick a different issue to work on, thanks.
I am creating a mixin that contains all the base test of TestBaseUserSerializer in accounts.tests.test_serializers and importing that mixin in addons.tests.test_serializers instead of the actual testcase class , so to avoid running it two times.