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

Method test_rewrite_ast

testing/test_assertion.py:246–289  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

244 result.stdout.fnmatch_lines([expected])
245
246 def test_rewrite_ast(self, pytester: Pytester) -> None:
247 pytester.mkdir("pkg")
248 contents = {
249 "pkg/__init__.py": """
250 import pytest
251 pytest.register_assert_rewrite('pkg.helper')
252 """,
253 "pkg/helper.py": """
254 def tool():
255 a, b = 2, 3
256 assert a == b
257 """,
258 "pkg/plugin.py": """
259 import pytest, pkg.helper
260 @pytest.fixture
261 def tool():
262 return pkg.helper.tool
263 """,
264 "pkg/other.py": """
265 values = [3, 2]
266 def tool():
267 assert values.pop() == 3
268 """,
269 "conftest.py": """
270 pytest_plugins = ['pkg.plugin']
271 """,
272 "test_pkg.py": """
273 import pkg.other
274 def test_tool(tool):
275 tool()
276 def test_other():
277 pkg.other.tool()
278 """,
279 }
280 pytester.makepyfile(**contents)
281 result = pytester.runpytest_subprocess("--assert=rewrite")
282 result.stdout.fnmatch_lines(
283 [
284 ">*assert a == b*",
285 "E*assert 2 == 3*",
286 ">*assert values.pop() == 3*",
287 "E*AssertionError",
288 ]
289 )
290
291 def test_register_assert_rewrite_checks_types(self) -> None:
292 with pytest.raises(TypeError):

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
mkdirMethod · 0.45
makepyfileMethod · 0.45
runpytest_subprocessMethod · 0.45

Tested by

no test coverage detected