Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to use mocker and reset os.remove #850

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import pytest
import requests_mock
from pytest import FixtureRequest, MonkeyPatch
from pytest import FixtureRequest
from pytest_mock import MockerFixture
from requests_mock import Mocker
from vcr import VCR # type: ignore
Expand Down Expand Up @@ -1449,7 +1449,6 @@ def test_zips_media_files_from_deck_notes(
self,
next_deterministic_uuid: Callable[[], uuid.UUID],
mocker: MockerFixture,
monkeypatch: MonkeyPatch,
):
client = AnkiHubClient(local_media_dir_path_cb=lambda: TEST_MEDIA_PATH)

Expand All @@ -1460,9 +1459,8 @@ def test_zips_media_files_from_deck_notes(
mocker.patch.object(client, "_upload_file_to_s3_with_reusable_presigned_url")

deck_id = next_deterministic_uuid()
with monkeypatch.context() as m:
m.setattr("os.remove", Mock())
self._upload_media_for_notes_data(client, notes_data, deck_id)
mocked_remove = mocker.patch("os.remove")
self._upload_media_for_notes_data(client, notes_data, deck_id)

# We will create and check for just one chunk in this test
path_to_created_zip_file = Path(
Expand All @@ -1476,6 +1474,7 @@ def test_zips_media_files_from_deck_notes(
assert set(zip_ref.namelist()) == set(all_media_names_in_notes)

# Remove the zipped file at the end of the test
mocker.stop(os.remove)
os.remove(path_to_created_zip_file)
assert path_to_created_zip_file.is_file() is False

Expand Down
Loading