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

Fix test issue where warning was being raised but not captured #151

Merged
merged 6 commits into from
Apr 8, 2024
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
24 changes: 16 additions & 8 deletions parfive/tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,14 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def run(self):
self.result = self._target(*self._args, **self._kwargs)
try:
self.result = self._target(*self._args, **self._kwargs)
finally:
del self._target, self._args, self._kwargs


@skip_windows
def test_download_out_of_main_thread(httpserver, tmpdir):
def test_download_out_of_main_thread(httpserver, tmpdir, recwarn):
tmpdir = str(tmpdir)
httpserver.serve_content(
"SIMPLE = T", headers={"Content-Disposition": "attachment; filename=testfile.fits"}
Expand All @@ -593,11 +596,16 @@ def test_download_out_of_main_thread(httpserver, tmpdir):

thread = CustomThread(target=dl.download)
thread.start()

with pytest.warns(
UserWarning,
match="This download has been started in a thread which is not the main thread. You will not be able to interrupt the download.",
):
thread.join()
thread.join()

validate_test_file(thread.result)

Cadair marked this conversation as resolved.
Show resolved Hide resolved
# We use recwarn here as for some reason pytest.warns did not reliably pickup this warning.
Cadair marked this conversation as resolved.
Show resolved Hide resolved
assert len(recwarn) > 0
assert any(
[
"This download has been started in a thread which is not the main thread. You will not be able to interrupt the download."
== w.message.args[0]
for w in recwarn
]
)
Loading