diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -5,8 +5,7 @@ import stat import sys import unittest -from test.support import run_unittest, TESTFN, verbose, requires, \ - unlink +from test.support import TESTFN, verbose, requires, unlink, use_resources import io # C implementation of io import _pyio as pyio # Python implementation of io @@ -23,7 +22,7 @@ size = 2500000000 -class LargeFileTest(unittest.TestCase): +class LargeFileTest: """Test that each file function works as expected for a large (i.e. > 2GB, do we have to check > 4GB) files. @@ -103,8 +102,6 @@ if verbose: print('try truncate') with self.open(TESTFN, 'r+b') as f: - # this is already decided before start running the test suite - # but we do it anyway for extra protection if not hasattr(f, 'truncate'): raise unittest.SkipTest("open().truncate() not available on this system") f.seek(0, 2) @@ -141,8 +138,7 @@ f.seek(pos) self.assertTrue(f.seekable()) - -def test_main(): +def setUpModule(): # On Windows and Mac OSX this test comsumes large resources; It # takes a long time to build the >2GB file and takes >2GB of disk # space therefore the resource must be enabled to run this test. @@ -168,25 +164,26 @@ raise unittest.SkipTest("filesystem does not have largefile support") else: f.close() + +def load_tests(*args): + # Order of tests is important, so add them explicitly suite = unittest.TestSuite() for _open, prefix in [(io.open, 'C'), (pyio.open, 'Py')]: - class TestCase(LargeFileTest): - pass - TestCase.open = staticmethod(_open) - TestCase.__name__ = prefix + LargeFileTest.__name__ + TestCase = type(prefix + LargeFileTest.__name__, + (LargeFileTest, unittest.TestCase), + {'open': staticmethod(_open)}) suite.addTest(TestCase('test_seek')) suite.addTest(TestCase('test_osstat')) suite.addTest(TestCase('test_seek_read')) suite.addTest(TestCase('test_lseek')) - with _open(TESTFN, 'wb') as f: - if hasattr(f, 'truncate'): - suite.addTest(TestCase('test_truncate')) + suite.addTest(TestCase('test_truncate')) suite.addTest(TestCase('test_seekable')) - unlink(TESTFN) - try: - run_unittest(suite) - finally: - unlink(TESTFN) + + return suite + +def tearDownModule(): + unlink(TESTFN) if __name__ == '__main__': - test_main() + use_resources = ['largefile'] + unittest.main()