xxx() missing 1 required positional argument: 'mocker'
See original GitHub issueI’m using pytest 5.3.0 with pytest-mock 1.12.1, and in a pytest class I want to temporarily mock a function of an object returned by some other module function. When I use test_calls_operation(mocker)
outside a test class, then the mocker
arg gets filled in by pytest-mock as expected. However, when I declare the test as shown below, I get test_calls_operation() missing 1 required positional argument: 'mocker'
. What am I doing wrong? I sifted through the documentation and especially StackOverflow, but I seem to miss the knack of getting the mocker
arg` automatically set as needed.
class KeysModuleTests(TestCase):
def test_calls_operation(self, mocker):
keys = mnt.keys.end()
mocker.spy(keys, 'op_end')
# ...
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
Missing 1 required positional argument: 'its' - Stack Overflow
when executing this code, an error occurs: TypeError: j1() missing 1 required positional argument: 'its' elif id == 526891231 and "/remove" ...
Read more >9 Testing - Data Pipelines with Apache ... - liveBook · Manning
Mimicking a DAG run to test tasks which apply templating; Faking requests and responses to external systems with mocking to keep tests self-contained;...
Read more >Cheat Sheet of Python Mock - Ines Panker
Level 1: Creating a new Mock object · Level 2: Missing attributes · Level 3: The attribute with the very unfortunate name -...
Read more >Introduction | The Function of Humour in Roman Verse Satire
Humour may lead the eye away from a weak point in the argument, ... Those who adopt the latter position, a more modern...
Read more >pact-python
2.6.1 - Fix issue where mocked `urlopen` didn't handle the correct number of positional arguments ```. bethskurrie. 2018-12-20 23:15.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@TheDiveO
pytest fixtures cannot be used in
unittest.TestCase
test methods. Theunittest
integration in pytest uses theunittest
Runner to actually run the tests, and the unittest runner doesn’t know about fixtures (this applies to any fixture, not onlymocker
).One workaround is to use an autouse fixture (which work un
unittest.TestCase
subclasses) to obtain the fixture you are interested in, then use it later. Example:Closing for now but feel free to follow up with further questions.
It returns missing 1 required positional argument 😔