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

Unit tests failing on mac os #149

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ABHISHEKSONI121
Copy link
Collaborator

@ABHISHEKSONI121 ABHISHEKSONI121 commented Mar 22, 2024

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

  • Classes, Variables, function and methods logic ok
  • Comments written explaining what the code does
  • All python code is PEP8 compliant (run black .)
  • No lint issues (run flake8)
  • Test coverage with pytest implemented
  • Reviewers assigned (at least 1 mentor)

Manual test evidence

@ABHISHEKSONI121 ABHISHEKSONI121 changed the title Unit tests failing on mac os (fixes issue#147) Unit tests failing on mac os Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant