Ordering Of Pytest Fixtures And Mock Patch Objects

If you’re using the mock library and pytest’s fixtures, then you might be confused for a second about the ordering. Mock objects go first and then pytests fixtures.

Here is an example:

import mock
import os
import pytest

def person():
    return Person(fname='test', lname='person')

@mock.patch.object(another, 'example')
@mock.patch.object(os, 'remove')
def test_remove_person_file(mock_remove, mock_example, person):
    # Remove the persons file
    os.remove('{}-{}.txt'.format(person.fname, person.lname))