Coverage for tests / test_callback_warning.py: 100%

26 statements  

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

1import pytest 1abcdefgh

2import typer 1abcdefgh

3from typer.testing import CliRunner 1abcdefgh

4 

5runner = CliRunner() 1abcdefgh

6 

7 

8def test_warns_when_callback_is_not_supported(): 1abcdefgh

9 app = typer.Typer() 1abcdefgh

10 

11 sub_app = typer.Typer() 1abcdefgh

12 

13 @sub_app.callback() 1abcdefgh

14 def callback(): 1abcdefgh

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

16 

17 app.add_typer(sub_app) 1abcdefgh

18 

19 with pytest.warns( 1abcdefgh

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

21 ): 

22 try: 1abcdefgh

23 app() 1abcdefgh

24 except SystemExit: 1abcdefgh

25 pass 1abcdefgh

26 

27 

28def test_warns_when_callback_is_not_supported_added_after_add_typer(): 1abcdefgh

29 app = typer.Typer() 1abcdefgh

30 

31 sub_app = typer.Typer() 1abcdefgh

32 app.add_typer(sub_app) 1abcdefgh

33 

34 @sub_app.callback() 1abcdefgh

35 def callback(): 1abcdefgh

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

37 

38 with pytest.warns( 1abcdefgh

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

40 ): 

41 try: 1abcdefgh

42 app() 1abcdefgh

43 except SystemExit: 1abcdefgh

44 pass 1abcdefgh