title: Pytest changes the behaviour of a generator recursive function
body: <p>This is my code:
  where 'schema' and 'config' are heavily nested dictionaries, this function work as intended when run separately.</p>
  <pre><code>def find_config_difference(schema, config, key_name=None):
      for k in schema:
          try:
              if &quot;default&quot; in schema[k] and k in config:
                  if schema[k][&quot;default&quot;] != config[k]:
                      out_of_date_default.append(f&quot;key {k} in {key_name} has out of date default value.&quot;)
                  schema[k] = schema[k][&quot;default&quot;]
          except TypeError:
              pass
          finally:
              if k in config:
                  if isinstance((schema[k] and config[k]), dict):
                      find_config_difference(schema[k], config[k], key_name=k)
              else:
                  yield f&quot;{k} in {key_name} is missing/extra in config&quot;
  
  output = list(find_config_difference(schema, config))
  </code></pre>
  <p>This is my pytest code :
  when run through pytest it does not call the function recursively and 'for' loop only goes through the outermost keys of 'schema'.</p>
  <pre><code>import unittest
  from unittest.mock import patch
  from config_compare import *
  import ast
  
  config = ast.literal_eval(open('config.json', 'r').read())
  schema = ast.literal_eval(open('config_schema.json', 'r').read())
  
  
  class Test_config_compare(unittest.TestCase):
  
  
      def test_find_config_difference(self):
          missing = list(find_config_difference(schema, config, key_name=None))
          length = len(missing)
          print(length)
  
  </code></pre>
  <p>Here is a section of 'schema', which is almost similar to 'config'.
  it would only iterate through keys($schema, additionalProperties, definitions, button_content)</p>
  <pre><code>schema = {
      &quot;$schema&quot;: &quot;http://json-schema.org/draft-07/schema#&quot;,
      &quot;additionalProperties&quot;: false,
      &quot;definitions&quot;: {
          &quot;color_hex&quot;: {&quot;pattern&quot;: &quot;^#([A-Fa-f0-9]{6})$&quot;, &quot;type&quot;: &quot;string&quot;},
          &quot;palette&quot;: {
              &quot;additionalProperties&quot;: false,
              &quot;properties&quot;: {
                  &quot;background&quot;: {&quot;$ref&quot;: &quot;#/definitions/color_hex&quot;, &quot;default&quot;: &quot;#FFFFFF&quot;},
                  &quot;primary&quot;: {
                      &quot;rules&quot;: {&quot;testTR&quot;: 12, &quot;tier&quot;: 2},
                  },
              },
          },
      },
      &quot;button_content&quot;: {
          &quot;additionalProperties&quot;: false,
          &quot;properties&quot;: {
              &quot;accessibilityLabel&quot;: {&quot;type&quot;: &quot;string&quot;},
          },
          &quot;required&quot;: [&quot;accessibilityLabel&quot;, &quot;value&quot;],
          &quot;type&quot;: &quot;object&quot;,
      },
  }
  </code></pre>
  <p>When I removed the yield generator it works fine. But, I also don't want to remove it and store the string in a variable. So is there a way to work around it?</p>