Skip to content

Using NamedTemporaryFile doesn't behave as expected on Windows #1

Closed
@matslindh

Description

@matslindh
  • pytest-image-diff version: 0.0.7
  • Python version: 3.9.7
  • Operating System: Windows 10

Description

When attempting to write to a NamedTemporaryFile on Windows, the file can't be open when given to splinter. If the file is open, an "Access Denied" exception is raised.

What I Did

This can be fixed by making the temporary file persistent, allowing it to close and then removing it manually. I can create a PR to fix this, but my current solution is to replace line 55 in splinter.py with:

        with NamedTemporaryFile(suffix=".png", delete=False) as tf:
            temp_image_path = pathlib.Path(tf.name)

        try:
            browser.driver.save_screenshot(os.fspath(temp_image_path))
            result = image_regression(os.fspath(temp_image_path), threshold, suffix)
        finally:
            temp_image_path.unlink(missing_ok=True)

        return result

If this looks OK to you I'll create a proper PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions