Package: pytest-camel-collect
pytest-camel-collectAllow pytest to respect word boundaries of CamelCaseWords in class name patterns.Installationpipinstallpytest-camel-collectUsageThis plug-in augments the pattern matching ofpython_classesin yourpytest.ini,tox.ini, orsetup.cfgfile.A-(dash) now represents a CamelCase word boundary.[pytest]python_classes=Camel-*Camel-*will match class names likeCamelClubandCamelCamelCamel, but notCamelizer.Why?Mixin classes can be helpful to reduce boilerplate. One might use these mixin classes
to add tests verifying API response status codes when authenticated as different users:classForbidsAnonymousUsers:classTestAnonymousUsersAreForbidden:@pytest.fixturedefuser(self):returnAnonymousUser()deftest_anonymous_user_is_forbidden(self,response):assertresponse.status_code==401classForbidsNonAdmins:classTestNonAdminsAreForbidden:@pytest.fixturedefuser(self):returnUser(is_admin=False)deftest_non_admin_is_forbidden(self,response):assertresponse.status_code==401Now, these mixins can be used to declare "traits" of certain test environments:classDescribeMyAPIEndpoint(BaseAPITest):@pytest.fixturedefurl(self):return'/my-endpoint'classDescribeList(ForbidsAnonymousUsers,):@pytest.fixturedefmethod(self):return'GET'classDescribeCreate(ForbidsAnonymousUsers,ForbidsNonAdmins,):@pytest.fixturedefmethod(self):return'POST'As it goes, business requirements change, and the API endpoint must now respond differently
depending on the user's language.No sweat! As experts in nameology, we add well-named context classes to test other languages:classDescribeMyAPIEndpoint(BaseAPITest):# ...classDescribeCreate(ForbidsAnonymousUsers,ForbidsNonAdmins,):# ...classForEnglishSpeakers:@pytest.fixturedefuser(self,user):user.language='english'returnuserdefit_returns_english(self,response):assertresponse['message']=='Created new thing'classForSpanishSpeakers:@pytest.fixturedefuser(self,user):user.language='spanish'returnuserdefit_returns_spanish(self,response):assertresponse['message']=='Creado cosa nueva'Hmmm, but when pytest is executed, it doesn't collect our two new tests...Ah, right!python_classesinpytest.ini![pytest]python_classes=Test* Describe* For*Run pytest again and it picks up our tests! Oh, and also picks up
ourForbidsAnonymousUsersandForbidsNonAdminsmixins... but because
they don't inheritBaseAPITest, theresponsefixture doesn't exist,
and they fail.What ever will we do?Introducing: pytest-camel-collect, the pytest plugin enablingyou,
the hard-working, dependable, definitely-not-sleep-deprived developer
to explicitly match CamelCase words during pytest collection.No longer must you run tests from yourForbidsAnonymousUsersmixin,
just because you also want to run tests in yourForSpanishSpeakerscontext!Hell no![pytest]python_classes=Test-* Describe-* For-*That's the spirit! Now,TestStuffwill be collected, but notTestimony;DescribeStuffwill be collected, but notDescribesCosas; and most importantly,ForSpanishSpeakerswill be collected, but notForbidsAnonymousUsers.DevelopmentTo play around with the project and run its tests:Clone the repoIn a virtualenv (or whatever you wanna do, I don't control you), runpip install -e .[dev,test]Runpy.testto run the tests