Last active
July 8, 2018 05:14
-
-
Save gaizeror/958252cad315a7d04a66054da0f4f081 to your computer and use it in GitHub Desktop.
inner function test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'...} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 == {}