Skip to content
Advertisement

Python add pytest –black to test suite

I use pytest for testing my Python project. What I want to do is to add to my test suite a function to check whether my code is formatted in “Black” or not. When I press the command "pytest --black" my whole project is tested as I want to. How can I add this function in my tests suite and check the same thing when I run the "python setup.py pytest" command?

Advertisement

Answer

pytest.ini has an addopts key which does literally what it says on the tin: it adds options to the pytest command line you used.

So at the root of your program, you should be able to just create a pytest.ini file containing:

[pytest]
addopts = --black

and it should automatically enable black-as-test on your pytest runs.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement