Coverage for tests / test_callback_warning.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-26 21:46 +0000

1import pytest 1abcdefg

2import typer 1abcdefg

3from typer.testing import CliRunner 1abcdefg

4 

5runner = CliRunner() 1abcdefg

6 

7 

8def test_warns_when_callback_is_not_supported(): 1abcdefg

9 app = typer.Typer() 1abcdefg

10 

11 sub_app = typer.Typer() 1abcdefg

12 

13 @sub_app.callback() 1abcdefg

14 def callback(): 1abcdefg

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

16 

17 app.add_typer(sub_app) 1abcdefg

18 

19 with pytest.warns( 1abcdefg

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

21 ): 

22 try: 1abcdefg

23 app() 1abcdefg

24 except SystemExit: 1abcdefg

25 pass 1abcdefg

26 

27 

28def test_warns_when_callback_is_not_supported_added_after_add_typer(): 1abcdefg

29 app = typer.Typer() 1abcdefg

30 

31 sub_app = typer.Typer() 1abcdefg

32 app.add_typer(sub_app) 1abcdefg

33 

34 @sub_app.callback() 1abcdefg

35 def callback(): 1abcdefg

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

37 

38 with pytest.warns( 1abcdefg

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

40 ): 

41 try: 1abcdefg

42 app() 1abcdefg

43 except SystemExit: 1abcdefg

44 pass 1abcdefg