From ec3ccaace17ac57671f2eca6eed5209e3940a857 Mon Sep 17 00:00:00 2001 From: Derek Ditch Date: Fri, 12 Aug 2022 13:19:12 -0500 Subject: [PATCH] Passes pyproject.toml to black, if present --- pytest_black.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pytest_black.py b/pytest_black.py index 04c80cb..dc52b75 100644 --- a/pytest_black.py +++ b/pytest_black.py @@ -47,9 +47,11 @@ def __init__(self, fspath, parent): super(BlackItem, self).__init__(fspath, parent) self._nodeid += "::BLACK" self.add_marker("black") + self.pyproject_present = False try: with open("pyproject.toml") as toml_file: settings = toml.load(toml_file)["tool"]["black"] + self.pyproject_present = True if "include" in settings.keys(): settings["include"] = self._re_fix_verbose(settings["include"]) if "exclude" in settings.keys(): @@ -71,6 +73,8 @@ def setup(self): def runtest(self): cmd = [sys.executable, "-m", "black", "--check", "--diff", "--quiet", str(self.fspath)] + if self.pyproject_present: + cmd.extend(["--config", "pyproject.toml"]) try: subprocess.run( cmd, check=True, stdout=subprocess.PIPE, universal_newlines=True