Updated a couple of tests to use pytest-mock
This commit is contained in:
@@ -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/`
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user