Coverage for tests / test_callback_warning.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1import pytest 1abcdefghij

2import typer 1abcdefghij

3from typer.testing import CliRunner 1abcdefghij

4 

5runner = CliRunner() 1abcdefghij

6 

7 

8def test_warns_when_callback_is_not_supported(): 1abcdefghij

9 app = typer.Typer() 1abcdefghij

10 

11 sub_app = typer.Typer() 1abcdefghij

12 

13 @sub_app.callback() 1abcdefghij

14 def callback(): 1abcdefghij

15 """This help text is not used.""" 

16 

17 app.add_typer(sub_app) 1abcdefghij

18 

19 with pytest.warns( 1abcdefghij

20 match="The 'callback' parameter is not supported by Typer when using `add_typer` without a name" 

21 ): 

22 try: 1abcdefghij

23 app() 1abcdefghij

24 except SystemExit: 1abcdefghij

25 pass 1abcdefghij

26 

27 

28def test_warns_when_callback_is_not_supported_added_after_add_typer(): 1abcdefghij

29 app = typer.Typer() 1abcdefghij

30 

31 sub_app = typer.Typer() 1abcdefghij

32 app.add_typer(sub_app) 1abcdefghij

33 

34 @sub_app.callback() 1abcdefghij

35 def callback(): 1abcdefghij

36 """This help text is not used.""" 

37 

38 with pytest.warns( 1abcdefghij

39 match="The 'callback' parameter is not supported by Typer when using `add_typer` without a name" 

40 ): 

41 try: 1abcdefghij

42 app() 1abcdefghij

43 except SystemExit: 1abcdefghij

44 pass 1abcdefghij