[qa] fix unclosed files problems in tests.

This commit is contained in:
Romain Dorgueil
2017-05-28 23:15:40 +02:00
parent 3ca5f962d2
commit 2c2bc4fca9
4 changed files with 20 additions and 11 deletions

View File

@ -20,7 +20,8 @@ def test_write_pickled_dict_to_file(tmpdir):
context.step()
context.stop()
assert pickle.loads(fs.open(filename, 'rb').read()) == {'foo': 'bar'}
with fs.open(filename, 'rb') as fp:
assert pickle.loads(fp.read()) == {'foo': 'bar'}
with pytest.raises(AttributeError):
getattr(context, 'file')
@ -28,8 +29,8 @@ def test_write_pickled_dict_to_file(tmpdir):
def test_read_pickled_list_from_file(tmpdir):
fs, filename = open_fs(tmpdir), 'input.pkl'
fs.open(filename,
'wb').write(pickle.dumps([['a', 'b', 'c'], ['a foo', 'b foo', 'c foo'], ['a bar', 'b bar', 'c bar']]))
with fs.open(filename, 'wb') as fp:
fp.write(pickle.dumps([['a', 'b', 'c'], ['a foo', 'b foo', 'c foo'], ['a bar', 'b bar', 'c bar']]))
reader = PickleReader(path=filename)