From 397db0d72fb218669a9ecbff134fa9b392a14661 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sun, 10 May 2020 09:00:56 -0700 Subject: [PATCH] Updated a couple of tests to use pytest-mock --- tests/README.md | 3 ++- tests/test_catalina_10_15_1.py | 12 ++++++------ tests/test_catalina_10_15_4.py | 12 +++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/README.md b/tests/README.md index 01b6b0af..e99222eb 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,8 +1,9 @@ # Tests for osxphotos # ## Running Tests ## -Tests require pytest: +Tests require pytest and pytest-mock: `pip install pytest` +`pip install pytest-mock` To run the tests, do the following from the main source folder: `python -m pytest tests/` diff --git a/tests/test_catalina_10_15_1.py b/tests/test_catalina_10_15_1.py index 8e2cc754..1b9bd907 100644 --- a/tests/test_catalina_10_15_1.py +++ b/tests/test_catalina_10_15_1.py @@ -106,17 +106,17 @@ def test_init4(): except: pass - -def test_init5(): +def test_init5(mocker): # test failed get_last_library_path import osxphotos - + def bad_library(): return None - # force get_last_library to return a bad path for testing - osxphotos.photosdb.get_last_library_path = bad_library - + # get_last_library actually in utils but need to patch it in photosdb because it's imported into photosdb + # as: from .utils import get_last_library + mocker.patch("osxphotos.photosdb.get_last_library_path", new=bad_library) + with pytest.raises(Exception): assert osxphotos.PhotosDB() diff --git a/tests/test_catalina_10_15_4.py b/tests/test_catalina_10_15_4.py index 2e076aa3..3645c749 100644 --- a/tests/test_catalina_10_15_4.py +++ b/tests/test_catalina_10_15_4.py @@ -107,19 +107,21 @@ def test_init4(): pass -def test_init5(): +def test_init5(mocker): # test failed get_last_library_path import osxphotos - + def bad_library(): return None - # force get_last_library to return a bad path for testing - osxphotos.photosdb.get_last_library_path = bad_library - + # get_last_library actually in utils but need to patch it in photosdb because it's imported into photosdb + # as: from .utils import get_last_library + mocker.patch("osxphotos.photosdb.get_last_library_path", new=bad_library) + with pytest.raises(Exception): assert osxphotos.PhotosDB() + def test_db_len(): import osxphotos