@@ -72,34 +72,40 @@ def test_shell_show(self):
7272                    'Test' , UserWarning , 'test_warning.py' , 99 , f , 'Line of code' )
7373            self .assertEqual (shellmsg .splitlines (), f .getvalue ().splitlines ())
7474
75+ 
7576class  TestDeprecatedHelp (unittest .TestCase ):
76-     def  setUp (self ):
77-         self .module  =  ModuleType ("testmodule" )
78-         self .code  =  r"""\ 
77+ 
78+     def  test_help_output (self ):
79+         # Capture the help output 
80+         import  io 
81+         from  contextlib  import  redirect_stdout 
82+         code  =  r"""\ 
7983from warnings import deprecated 
8084@deprecated("Test") 
8185class A: 
8286    pass 
8387""" 
84-         exec (self .code , self .module .__dict__ )
85-         sys .modules ["testmodule" ] =  self .module 
88+         subclass_code  =  r"""\ 
89+ from warnings import deprecated 
90+ @deprecated("Test") 
91+ class A: 
92+     pass 
8693
87-     def  tearDown (self ):
88-         if  "testmodule"  in  sys .modules :
94+ class B(A): 
95+     pass 
96+ b = B() 
97+ """ 
98+         module  =  ModuleType ("testmodule" )
99+         for  kode  in  (code ,subclass_code ):
100+             exec (kode , module .__dict__ )
101+             sys .modules ["testmodule" ] =  module 
102+             f  =  io .StringIO ()
103+             with  redirect_stdout (f ):
104+                 help (module )
105+             help_output  =  f .getvalue ()
106+             self .assertIn ("Help on module testmodule:" , help_output )
89107            del  sys .modules ["testmodule" ]
90108
91-     def  test_help_output (self ):
92-         # Capture the help output 
93-         import  io 
94-         from  contextlib  import  redirect_stdout 
95- 
96-         f  =  io .StringIO ()
97-         with  redirect_stdout (f ):
98-             help (self .module )
99- 
100-         help_output  =  f .getvalue ()
101- 
102-         self .assertIn ("Help on module testmodule:" , help_output )
103109
104110if  __name__  ==  '__main__' :
105111    unittest .main (verbosity = 2 )
0 commit comments