title: How can I unittest an Enum's __init__ method?
body: <p>I'm struggling to unit test the <code>__init__</code> method on an enumeration I'm using. The difficulty is that I can't extend the enum (so can't implicitly call <code>__init__</code>). When I try to directly call it from my test it insists that the first parameter should be an instance of that enum. I can't do this, because I can't assume any of the enum's properties in advance.</p>
  
  <p>With a contrived example of the problem, let's say I have an enum of even numbers:</p>
  
  <pre><code>class EvenNumbers(Enum):
     two = 2
     four = 4
  </code></pre>
  
  <p>I want to do some value checking so that no-one accidentally adds an odd number to this enum:</p>
  
  <pre><code>class EvenNumbers(Enum):
     two = 2
     four = 4
  
     def __init__(self, value):
        assert value % 2 == 0
  </code></pre>
  
  <p>Now I want to write a test to make sure that this works. Two approaches seem intuitive but don't work:</p>
  
  <pre><code>def test_approach_1():
      '''
      Try to extend the Enum with a bad value. This fails
      because I can't extend an Enum.
      '''
  
      class BadEnum(EvenNumbers):
          three = 3
  
  def test_approach_2():
      '''
      Try to call the __init__ method directly. This fails
      because I need to supply an instance of the enum as
      the first parameter and I can't assume any values are
      available.
      '''
  
      EvenNumbers.__init__(None, 3)
  </code></pre>
  
  <p>How should I unit test my <code>__init__</code> method?</p>