Skip to content

Instantly share code, notes, and snippets.

@gaizeror
Last active July 8, 2018 05:14
Show Gist options
  • Save gaizeror/958252cad315a7d04a66054da0f4f081 to your computer and use it in GitHub Desktop.
Save gaizeror/958252cad315a7d04a66054da0f4f081 to your computer and use it in GitHub Desktop.
inner function test
b.py:
def get_yaml_data(account_id):
return get_data('bla/%s.yaml' % account_id).data
a.py:
from path.to.b.py import get_yaml_data
class Example(object):
def get_enriched_yaml_data(self):
data = get_yaml_data('example')
# data enrichement that add key/val to data dict
return data
test_file:
from path.to.a import Example
@fixture
def example_conf():
return Example(arg1=val1,arg2=val2)
def test_empty_data(example_conf):
**** somehow to simulate empty list returned from b.get_yaml_data ***
result = Example.get_enriched_yaml_data()
assert result == {'key': 'val'...}
@AvihayTsayeg
Copy link

AvihayTsayeg commented Jul 5, 2018

b.py

def get_yaml_data(account_id):
return {"a":"a", "b":"b", "c":"c"}

a.py

from b import get_yaml_data

class Example(object):
def get_enriched_yaml_data(self):
data = get_yaml_data('example')
# data enrichement that add key/val to data dict
return data

testa.py

from mock import patch

from a import Example

def test_empty_data():
with patch('a.get_yaml_data') as mock_b:
mock_b.return_value = {}
result = Example().get_enriched_yaml_data()
assert result == {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment