3

I'm learning to use mock when testing with pytest.

I got a simple test function:

import pytest
import smtplib

def test_send_email():
    with mocker.patch('smtplib.SMTP') as mock:
        assert True

But when I try to run this test I got the following error: NameError: name 'mocker' is not defined.

I already verified that mock, pytest and pytest-mock are correctly installed.

What am I doing wrong ?

APianist
  • 291
  • 1
  • 4
  • 14

1 Answers1

2

Welll. was a stupide error... I was missing the mocker parameter...

It should be:

def test_send_email(mocker):
    with mocker.patch('smtplib.SMTP') as mock:
        assert True
APianist
  • 291
  • 1
  • 4
  • 14
  • I couldn't figure this out either lol - seems I missed the fact that they were passing a param in the doc examples – takanuva15 Mar 02 '23 at 18:02