|
1 | 1 | import fnmatch |
2 | | -import os |
| 2 | +import io |
3 | 3 | import sys |
4 | 4 | from pathlib import Path |
5 | 5 | from typing import Set, Tuple |
@@ -69,7 +69,7 @@ class FixtureChecker(BasePytestChecker): |
69 | 69 | ( |
70 | 70 | "pylint-pytest plugin cannot enumerate and collect pytest fixtures. " |
71 | 71 | "Please run `pytest --fixtures --collect-only %s` and resolve " |
72 | | - "any potential syntax error or package dependency issues" |
| 72 | + "any potential syntax error or package dependency issues. stdout: %s. stderr: %s." |
73 | 73 | ), |
74 | 74 | "cannot-enumerate-pytest-fixtures", |
75 | 75 | "Used when pylint-pytest has been unable to enumerate and collect pytest fixtures.", |
@@ -116,11 +116,12 @@ def visit_module(self, node): |
116 | 116 | is_test_module = True |
117 | 117 | break |
118 | 118 |
|
| 119 | + stdout, stderr = sys.stdout, sys.stderr |
119 | 120 | try: |
120 | | - with open(os.devnull, "w") as devnull: |
| 121 | + with io.StringIO() as captured_stdout, io.StringIO() as captured_stderr: |
121 | 122 | # suppress any future output from pytest |
122 | | - stdout, stderr = sys.stdout, sys.stderr |
123 | | - sys.stderr = sys.stdout = devnull |
| 123 | + sys.stderr = captured_stderr |
| 124 | + sys.stdout = captured_stdout |
124 | 125 |
|
125 | 126 | # run pytest session with customized plugin to collect fixtures |
126 | 127 | fixture_collector = FixtureCollector() |
@@ -155,9 +156,18 @@ def visit_module(self, node): |
155 | 156 | ) |
156 | 157 | ) |
157 | 158 | if (ret != pytest.ExitCode.OK or legitimate_failure_paths) and is_test_module: |
| 159 | + files_to_report = { |
| 160 | + str(Path(x).absolute().relative_to(Path.cwd())) |
| 161 | + for x in legitimate_failure_paths | {node.file} |
| 162 | + } |
| 163 | + |
158 | 164 | self.add_message( |
159 | 165 | "cannot-enumerate-pytest-fixtures", |
160 | | - args=" ".join(legitimate_failure_paths | {node.file}), |
| 166 | + args=( |
| 167 | + " ".join(files_to_report), |
| 168 | + captured_stdout.getvalue(), |
| 169 | + captured_stderr.getvalue(), |
| 170 | + ), |
161 | 171 | node=node, |
162 | 172 | ) |
163 | 173 | finally: |
|
0 commit comments