Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The initial problem was that the tests were failing on macOS because they were trying to use os.startfile, a function that only exists on Windows. This function is used to open a file with its associated application.
Created a platform-independent function: To solve this, I created a new function open_file that behaves like os.startfile on all platforms. On Windows, it uses os.startfile, and on macOS, it uses the open command via subprocess.call.
Patched the function in tests: used the mocker.patch function from the pytest-mock library to replace os.startfile with our new open_file function during testing. This allowed the tests to run successfully on all platforms.
Handled AttributeError: Initially, faced an AttributeError because os.startfile does not exist on macOS and Linux. To handle this, I added the create=True argument to mocker.patch, which tells it to create the attribute if it doesn't exist.
Applied the fix to all tests: initially applied the fix to one test, but then realized that the same problem was occurring in other tests as well. So, applied the same fix to all tests that were using os.startfile.
By doing this, made the tests platform-independent, meaning they can now run successfully on Windows, macOS, and Linux.
fixes issue#147
Checklist
Manual test evidence