title: Code Coverage: How to write 100% coverage tests in pytest for functions having except KeyboardInterrupt blocks?
body: <p>I have a function which catches KeyboardInterrupts for additional functionalities and I have to write tests in pytest and I don't know how to create a testcase to cover the KeyboardInterrupt catch block.</p>
  <p>The code is similar to this:</p>
  <pre><code># main_game.py
  class Cache:
      other_details = dict()
  
  def save_progress_for_future(progress):
      file = open('progress.json', 'w')
      content = {'progress_percent':progress, **other_details}
      json.dump(content, file)
      file.close()
  
  def loadingBar():
      progress = 0
      while True:
          try:
              ...  # other stuff
              progress = get_progress_percent()
              print('\r Loading' + str('.' * progress//10) + '\r', end='')
          except KeyboardInterrupt:
              save_progress_in_file(progress)
  
  </code></pre>
  <p>How am I going to write tests in pytest in other tests file (say test_main_game.py) to cover the KeyboardInterrupt part, and so that coverage cli tool shows 100% of code coverage in its report?</p>