title: How to call a function within a function from a module
body: <p>I'm having an issue when I attempt to unit test my code. I have a script named &quot;compute_stats2.py&quot; which contains a defined function &quot;compute_stats&quot; within a function &quot;main&quot; because I want to build in a command line argument within main later down the line. The functions used in compute_stats are all defined within main, but I excluded them for the sake of neatness, please let me know if you need to take a look at it. That being said I have been attempting to unit test (see code below) and every time I attempt to run the test this error occurs.</p>
  <blockquote>
  <p>AttributeError: module 'compute_stats2' has no attribute 'compute_stats'</p>
  </blockquote>
  <p>I'm wondering if I'm not calling the function correctly within the unit test code. Any suggestions on how to make that call better.</p>
  <p>P.S. apologizes in advance if it's a really obvious fix, I'm not the strongest coder.</p>
  <hr />
  <h1>compute_stats2.py</h1>
  <pre><code>def main():
  
    def compute_stats(values):
      if not values:
        return None
      else:
        o_min=minimum_of_list(values)
        o_max=values[-1]
        o_avg=average_of_list(values)
        o_median=median_of_list(values)
        return(o_min, o_max, o_avg, o_median)
  if __name__ == '__main__':
    main()
  </code></pre>
  <hr />
  <h1>test_compute_stats2.py</h1>
  <pre><code>import unittest
  import compute_stats2
  
  class TestComputeStats2(unittest.TestCase):
  
  def test_none_from_none(list):
      ret = compute_stats2.compute_stats(None)
      list.assertIsNone(ret)
  
  def test_empty_list(list):
      ret = compute_stats2.compute_stats([])
      list.assertIsNone(ret)
  
  def test_even_elements_list(list):
      ret = compute_stats2.compute_stats([1,2,3,4])
      list.assertEqual(ret, (1, 4, 2.5, 2.5))
  
  def test_odd_elements_list(list):
      ret = compute_stats2.compute_stats([1,2,12])
      list.assertEqual(ret, (1, 12, 5, 2))
  
  def test_single_element_list(list):
      ret = compute_stats2.compute_stats([43])
      list.assertEqual(ret, (43, 43, 43, 43))
  </code></pre>