Questions tagged [flexmock]

flexmock refers to either a Ruby or Python testing library.

flexmock refers to either a or testing library, both of which are designed with simplicity and flexibility in mind. The Ruby implementation was the original library called "flexmock" and the Python version, while not a clone, is heavily influenced by it.

flexmock for Ruby

flexmock for Python

8 questions
5
votes
1 answer

Mocking not working with pytest and flexmock

I'm trying to use pytest fixtures to mock calls to open() and then reset it on test teardown, but for some reason the mock is not applied in the test function. Here's a sample of what I have: # tests.py @pytest.fixture(scope='module') def…
imiric
  • 8,315
  • 4
  • 35
  • 39
3
votes
1 answer

Mock user input()

I am trying to simulate user input for a python script that I have going using py.test. Here's some basic code that represents what I'm trying to accomplish: def ask(): while True: age = input("Enter your age: ") if int(age) <…
nbb
  • 295
  • 3
  • 10
1
vote
1 answer

How to mock classes or objects in a module under test with flexmock

I want to mock a function call in the body of the surrounding function which I'm testing. I need to do this with flexmock or at least know if it's not possible. Take the following piece of code as an example. I have 3 files. utils.py with a single…
1
vote
0 answers

Is there a way to remove flexmock from an object?

You've mocked this module/object: flexmock(foo) Is there any way to reverse this process, so that when you call into foo, you can be sure that you're not hitting a mocked method? This would enable testing different components in isolation. If I…
Eamonn M.R.
  • 1,917
  • 2
  • 17
  • 23
1
vote
1 answer

Using flexmock on python modules

I've been searching on internet to find an example of using flexmock on python modules, but all doc's seem to be for object/class. I'm wondering if it's possible to mock some variables returned by a module. What if that module calls another…
JChao
  • 2,178
  • 5
  • 35
  • 65
1
vote
1 answer

Flexmock a django model object gives model objects?

I am trying to flexmock a django model object, but when I mock it then also it gives me that object itself. How can I mock it then ? So there was a model object I created in a method like this aa = ModelName() now when I tried to mock it, like…
NIlesh Sharma
  • 5,445
  • 6
  • 36
  • 53
0
votes
1 answer

How to write test case for the extra functionality added after mock

from flexmock import flexmock class Addition: def add(self,num1,num2): return num1+num2 creating a mock mock=Addition() flexmock(mock) mock.should_receive('add') assert mock.add(1,2)==3 I have mocked the Addition class using…
Tara Prasad Gurung
  • 3,422
  • 6
  • 38
  • 76
0
votes
1 answer

MagicMock return value based on input

I am trying to refactor my tests from flexmock to mock. Given the following syntax from flexmock: flexmock(subprocess).should_receive('check_output').with_args('ls /').and_return(output) How can I rewrite this using Mock? In particular, how do I…
Jon Skarpeteig
  • 4,118
  • 7
  • 34
  • 53