TheDigitalCatOnline / blog_source

Source code of the blog
16 stars 6 forks source link

code? in TDD in Python with pytest - Part 5 #20

Open 4myhw opened 3 years ago

4myhw commented 3 years ago

Currently the patch for datetime.now that illustrates the TypeError is: @patch('datetime.datetime.now') Should it be: @patch('fileinfo.logger.datetime.datetime.now')

The other is very minor and not an error just something to make things simpler. The order of lines of code was switched while you were demonstrating multiple with statements. Just in case someone agrees with you and thinks assert_called_with is less awkward then multiple withs and skips to the next piece of code:

Under Multiple patches:

@patch('os.path.getsize')
@patch('os.path.abspath')
def test_get_info(abspath_mock, getsize_mock):
    filename = 'somefile.ext'
    original_path = '../{}'.format(filename)

    test_abspath = 'some/abs/path'
    abspath_mock.return_value = test_abspath

Under Checking call parameters:

@patch('os.path.getsize')
@patch('os.path.abspath')
def test_get_info(abspath_mock, getsize_mock):
    test_abspath = 'some/abs/path'
    abspath_mock.return_value = test_abspath

    filename = 'somefile.ext'
    original_path = '../{}'.format(filename)
lgiordani commented 3 years ago

Thanks for spotting the inverted lines of code. As for the first one, my original intention was to explain that we shall not patch the original module, but the imported one, and I realise that I mixed this concept with the strategies to patch dates. I will fix it asap (it requires changing the code of the package as well)