|
20 | 20 | import logging |
21 | 21 | import struct |
22 | 22 | import test.support |
| 23 | +import test.script_helper |
23 | 24 |
|
24 | 25 |
|
25 | 26 | # Skip tests if _multiprocessing wasn't built. |
@@ -3346,9 +3347,29 @@ def test_timeout(self): |
3346 | 3347 | finally: |
3347 | 3348 | socket.setdefaulttimeout(old_timeout) |
3348 | 3349 |
|
| 3350 | +# |
| 3351 | +# Test what happens with no "if __name__ == '__main__'" |
| 3352 | +# |
| 3353 | + |
| 3354 | +class TestNoForkBomb(unittest.TestCase): |
| 3355 | + def test_noforkbomb(self): |
| 3356 | + name = os.path.join(os.path.dirname(__file__), 'mp_fork_bomb.py') |
| 3357 | + if WIN32: |
| 3358 | + rc, out, err = test.script_helper.assert_python_failure(name) |
| 3359 | + self.assertEqual('', out.decode('ascii')) |
| 3360 | + self.assertIn('RuntimeError', err.decode('ascii')) |
| 3361 | + else: |
| 3362 | + rc, out, err = test.script_helper.assert_python_ok(name) |
| 3363 | + self.assertEqual('123', out.decode('ascii').rstrip()) |
| 3364 | + self.assertEqual('', err.decode('ascii')) |
| 3365 | + |
| 3366 | +# |
| 3367 | +# |
| 3368 | +# |
| 3369 | + |
3349 | 3370 | testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, |
3350 | 3371 | TestStdinBadfiledescriptor, TestWait, TestInvalidFamily, |
3351 | | - TestFlags, TestTimeouts] |
| 3372 | + TestFlags, TestTimeouts, TestNoForkBomb] |
3352 | 3373 |
|
3353 | 3374 | # |
3354 | 3375 | # |
|
0 commit comments