Coverage for tests/test_callback_warning.py: 100%
26 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
1import pytest 1iabcdefgh
2import typer 1iabcdefgh
3from typer.testing import CliRunner 1iabcdefgh
5runner = CliRunner() 1iabcdefgh
8def test_warns_when_callback_is_not_supported(): 1iabcdefgh
9 app = typer.Typer() 1iabcdefgh
11 sub_app = typer.Typer() 1iabcdefgh
13 @sub_app.callback() 1iabcdefgh
14 def callback(): 1abcdefgh
15 """This help text is not used."""
17 app.add_typer(sub_app) 1iabcdefgh
19 with pytest.warns( 1iabcdefgh
20 match="The 'callback' parameter is not supported by Typer when using `add_typer` without a name"
21 ):
22 try: 1iabcdefgh
23 app() 1iabcdefgh
24 except SystemExit: 1iabcdefgh
25 pass 1iabcdefgh
28def test_warns_when_callback_is_not_supported_added_after_add_typer(): 1iabcdefgh
29 app = typer.Typer() 1iabcdefgh
31 sub_app = typer.Typer() 1iabcdefgh
32 app.add_typer(sub_app) 1iabcdefgh
34 @sub_app.callback() 1iabcdefgh
35 def callback(): 1abcdefgh
36 """This help text is not used."""
38 with pytest.warns( 1iabcdefgh
39 match="The 'callback' parameter is not supported by Typer when using `add_typer` without a name"
40 ):
41 try: 1iabcdefgh
42 app() 1iabcdefgh
43 except SystemExit: 1iabcdefgh
44 pass 1iabcdefgh