@@ -88,15 +88,17 @@ def test_pickle_roundtrip(self):
8888 parser = argparse .ArgumentParser (exit_on_error = False )
8989 parser .add_argument ('--foo' , type = int , default = 42 )
9090 parser .add_argument ('bar' , nargs = '?' , default = 'baz' )
91- # Try to pickle and unpickle the parser
92- parser2 = pickle .loads (pickle .dumps (parser ))
93- # Check that the round-tripped parser still works
94- ns = parser2 .parse_args (['--foo' , '123' , 'quux' ])
95- self .assertEqual (ns .foo , 123 )
96- self .assertEqual (ns .bar , 'quux' )
97- ns2 = parser2 .parse_args ([])
98- self .assertEqual (ns2 .foo , 42 )
99- self .assertEqual (ns2 .bar , 'baz' )
91+ for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
92+ with self .subTest (protocol = proto ):
93+ # Try to pickle and unpickle the parser
94+ parser2 = pickle .loads (pickle .dumps (parser , protocol = proto ))
95+ # Check that the round-tripped parser still works
96+ ns = parser2 .parse_args (['--foo' , '123' , 'quux' ])
97+ self .assertEqual (ns .foo , 123 )
98+ self .assertEqual (ns .bar , 'quux' )
99+ ns2 = parser2 .parse_args ([])
100+ self .assertEqual (ns2 .foo , 42 )
101+ self .assertEqual (ns2 .bar , 'baz' )
100102
101103
102104class TestCase (unittest .TestCase ):
0 commit comments