mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #32094 -- Fixed flush() calls on management command self.stdout/err proxies.
This commit is contained in:
		
				
					committed by
					
						
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							b7da588e88
						
					
				
				
					commit
					f1f24539d8
				
			@@ -140,6 +140,10 @@ class OutputWrapper(TextIOBase):
 | 
			
		||||
    def __getattr__(self, name):
 | 
			
		||||
        return getattr(self._out, name)
 | 
			
		||||
 | 
			
		||||
    def flush(self):
 | 
			
		||||
        if hasattr(self._out, 'flush'):
 | 
			
		||||
            self._out.flush()
 | 
			
		||||
 | 
			
		||||
    def isatty(self):
 | 
			
		||||
        return hasattr(self._out, 'isatty') and self._out.isatty()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								tests/user_commands/management/commands/outputwrapper.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								tests/user_commands/management/commands/outputwrapper.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
from django.core.management.base import BaseCommand
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Command(BaseCommand):
 | 
			
		||||
    def handle(self, **options):
 | 
			
		||||
        self.stdout.write('Working...')
 | 
			
		||||
        self.stdout.flush()
 | 
			
		||||
        self.stdout.write('OK')
 | 
			
		||||
@@ -341,6 +341,13 @@ class CommandTests(SimpleTestCase):
 | 
			
		||||
        parser = BaseCommand().create_parser('prog_name', 'subcommand', epilog=epilog)
 | 
			
		||||
        self.assertEqual(parser.epilog, epilog)
 | 
			
		||||
 | 
			
		||||
    def test_outputwrapper_flush(self):
 | 
			
		||||
        out = StringIO()
 | 
			
		||||
        with mock.patch.object(out, 'flush') as mocked_flush:
 | 
			
		||||
            management.call_command('outputwrapper', stdout=out)
 | 
			
		||||
        self.assertIn('Working...', out.getvalue())
 | 
			
		||||
        self.assertIs(mocked_flush.called, True)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CommandRunTests(AdminScriptTestCase):
 | 
			
		||||
    """
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user