Skip to content

Tests failing on macOS due to usage of os.startfile #147

@ABHISHEKSONI121

Description

@ABHISHEKSONI121

Description

Several unit tests are failing on macOS due to the usage of os.startfile, which is a Windows-specific function. The tests fail with an AttributeError: module 'os' has no attribute 'startfile'.

Affected Tests

The following tests are affected:

  • test_pyfepdf.py::test_mostrar_pdf
  • test_pyi25.py::test_main_mostrar
  • test_pyqr.py::test_main_mostrar

Suggested Fix

A possible fix is to create a platform-independent function that behaves like os.startfile on all platforms. On Windows, it can use os.startfile, and on macOS and Linux, it can use the open command via subprocess.call. This function can then be used to replace os.startfile during testing using mocker.patch.

Screenshot 2024-03-19 at 1 20 15 AM

Here's an example of how this function can look like:

def open_file(path):
    if platform.system() == "Windows":
        os.startfile(path)
    else:
        subprocess.call(["open", path])
        

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions