I'm not talking about parameterizing the fixture function , which allows you to repeatedly run the device for a hard-set set of parameters.
I have many tests that follow the pattern, for example:
httpcode = 401 # this is different per call message = 'some message' # this is different per call url = 'some url' # this is different per call mock_req = mock.MagicMock(spec_set=urllib2.Request) with mock.patch('package.module.urllib2.urlopen', autospec=True) as mock_urlopen, \ mock.patch('package.module.urllib2.Request', autospec=True) as mock_request: mock_request.return_value = mock_req mock_urlopen.side_effect = urllib2.HTTPError(url, httpcode, message, {}, None) connection = MyClass() with pytest.raises(MyException): connection.some_function() # this changes
Essentially, I have a class that is an API client, and includes custom, significant exceptions that wrap urllib2 errors in something specific to the API. So, I have this model - fixing some methods and setting side effects for one of them. I probably use it in a dozen different tests, and the only differences are the three variables that are used in the side_effect part and the MyClass () method that I call.
Is there any way to do this pytest fixture and pass these variables?
source share