MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_name

Method test_name

testing/test_assertrewrite.py:185–238  ·  view source on GitHub ↗
(self, request)

Source from the content-addressed store, hash-verified

183 pytester.runpytest().assert_outcomes(passed=1)
184
185 def test_name(self, request) -> None:
186 def f1() -> None:
187 assert False
188
189 assert getmsg(f1) == "assert False"
190
191 def f2() -> None:
192 f = False
193 assert f
194
195 assert getmsg(f2) == "assert False"
196
197 def f3() -> None:
198 assert a_global # type: ignore[name-defined] # noqa
199
200 assert getmsg(f3, {"a_global": False}) == "assert False"
201
202 def f4() -> None:
203 assert sys == 42 # type: ignore[comparison-overlap]
204
205 verbose = request.config.getoption("verbose")
206 msg = getmsg(f4, {"sys": sys})
207 if verbose > 0:
208 assert msg == (
209 "assert <module 'sys' (built-in)> == 42\n"
210 " +<module 'sys' (built-in)>\n"
211 " -42"
212 )
213 else:
214 assert msg == "assert sys == 42"
215
216 def f5() -> None:
217 assert cls == 42 # type: ignore[name-defined] # noqa: F821
218
219 class X:
220 pass
221
222 msg = getmsg(f5, {"cls": X})
223 assert msg is not None
224 lines = msg.splitlines()
225 if verbose > 1:
226 assert lines == [
227 f"assert {X!r} == 42",
228 f" +{X!r}",
229 " -42",
230 ]
231 elif verbose > 0:
232 assert lines == [
233 "assert <class 'test_...e.<locals>.X'> == 42",
234 f" +{X!r}",
235 " -42",
236 ]
237 else:
238 assert lines == ["assert cls == 42"]
239
240 def test_assertrepr_compare_same_width(self, request) -> None:
241 """Should use same width/truncation with same initial width."""

Callers

nothing calls this directly

Calls 2

getmsgFunction · 0.85
getoptionMethod · 0.45

Tested by

no test coverage detected