Chapter 5
Plugins

As powerful as pytest is right out of the box, it gets even better when you add plugins to the mix. The pytest code base is structured with customization and extensions, and there are hooks available to allow modifications and improvements through plugins.

It might surprise you to know that you’ve already written some plugins if you’ve worked through the previous chapters in this book. Any time you put fixtures and/or hook functions into a project’s top-level conftest.py file, you created a local conftest plugin. It’s just a little bit of extra work to convert these conftest.py files into installable plugins that you can share between projects, with other people, or with the world.

We will start this chapter looking at where to look for third-party plugins. Quite a few plugins are available, so there’s a decent chance someone has already written the change you want to make to pytest. Since we will be looking at open source plugins, if a plugin does almost what you want to do but not quite, you can fork it, or use it as a reference for creating your own plugin. While this chapter is about creating your own plugins, Appendix 3, Plugin Sampler Pack is included to give you a taste of what’s possible.

In this chapter, you’ll learn how to create plugins, and I’ll point you in the right direction to test, package, and distribute them. The full topic of Python packaging and distribution is probably a book of its own, so we won’t cover everything. But you’ll get far enough to be able to share plugins with your team. I’ll also discuss some shortcuts to getting PyPI–distributed plugins up with the least amount of work.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.176.72