I've written a function that creates a tarball.
# tarball.py
import os
import tarfile
def create_tarball():
with tarfile.open("path/to/tar/file", "w:gz") as tar:
tar.add(
"/path/to/included/directory",
arcname=os.path.basename("/path/to/included/directory"),
)
I've written a passing test with an assertion on the tarfile.open
context manager.
from unittest.mock import patch
from tarball import create_tarball
@patch("tarball.tarfile.open")
def test_create_tarball_partial(mock_open):
create_tarball()
mock_open.assert_called_with("path/to/tar/file", "w:gz")
How do I write a test for a function called inside the tarfile.open
context manager?