import unittest.mock


def _test_module_init(module, main_name="main"):
    with unittest.mock.patch.object(module, main_name, return_value=0):
        with unittest.mock.patch.object(module, "__name__", "__main__"):
            with unittest.mock.patch.object(module.sys, "exit") as exit:
                module.module_init()
                return exit.call_args[0][0] == 0

import unittest.mock


def _test_module_init(module, main_name="main"):
    with unittest.mock.patch.object(
        module, main_name, return_value=0
    ), unittest.mock.patch.object(
        module, "__name__", "__main__"
    ), unittest.mock.patch.object(
        module.sys, "exit"
    ) as exit:
        module.module_init()
        return exit.call_args[0][0] == 0

Use multiple context managers on one with statement (thanks Anna)
Use multiple context managers on one with statement (thanks Anna)

  import unittest.mock
  
  
  def _test_module_init(module, main_name="main"):
-     with unittest.mock.patch.object(module, main_name, return_value=0):
-         with unittest.mock.patch.object(module, "__name__", "__main__"):
-             with unittest.mock.patch.object(module.sys, "exit") as exit:
+     with unittest.mock.patch.object(
+         module, main_name, return_value=0
+     ), unittest.mock.patch.object(
+         module, "__name__", "__main__"
+     ), unittest.mock.patch.object(
+         module.sys, "exit"
+     ) as exit:
-                 module.module_init()
+         module.module_init()
-                 return exit.call_args[0][0] == 0
+         return exit.call_args[0][0] == 0
  
Use multiple context managers on one with statement (thanks Anna)
## Code Before:
import unittest.mock


def _test_module_init(module, main_name="main"):
    with unittest.mock.patch.object(module, main_name, return_value=0):
        with unittest.mock.patch.object(module, "__name__", "__main__"):
            with unittest.mock.patch.object(module.sys, "exit") as exit:
                module.module_init()
                return exit.call_args[0][0] == 0

## Instruction:
Use multiple context managers on one with statement (thanks Anna)
## Code After:
import unittest.mock


def _test_module_init(module, main_name="main"):
    with unittest.mock.patch.object(
        module, main_name, return_value=0
    ), unittest.mock.patch.object(
        module, "__name__", "__main__"
    ), unittest.mock.patch.object(
        module.sys, "exit"
    ) as exit:
        module.module_init()
        return exit.call_args[0][0] == 0
