Can I test a method inside a method in Python?
search.py
def SearchWeb(query=None):
"""Search via API"""
search = cool_api.api_request(query)
def _HandleResponse(search):
if search:
return search['result']
return _HandleResponse(search)
I want to create a test method for _HandleResponse
using unittest
search_test.py
import unittest
class MyTest(unittest.TestCase):
def test(self):
response = {}
response['result'] = 'yes'
self.assertEqual(search._HandleResponse(response), 'yes')
But _HandleResponse
is not accessible. I get:
AttributeError: 'module' object has no attribute '_HandleResponse'
I can move _HandleResponse
outside SearchWeb
method and that works, but wondering if this is possible?
Aucun commentaire:
Enregistrer un commentaire