Removing unnecesary line in test in Ellen's Alien Game

There is a line in one of the tests that tries to access a class attribute that doesn’t exist. While it isn’t breaking in any sense, that line is pointless. I’ve run the tests without the line that they pass appropriately.

Alien.health = 6

The exercise in question is: Ellen's Alien Game in Python on Exercism

I’m not used to contributing to public repositories, so I’m not sure I’m doing this right. Althoug the PR is closed, supposedly it would be opened after discussion happens here.

https://exercism.org/docs/community/being-a-good-community-member/chestertons-fence

Are you sure it’s unnecessary? Or might it be there to test something specific? Could that line be important to detect specific bugs that some implementations might have?

1 Like

Hah. Scratch that. I thought I might be able to write a solution that uses that line but I failed. That line looks like it might be attempting to check that an instance variable is used for the health, and not a class variable, along the lines of https://github.com/exercism/python/pull/4273

The test is not trying to access the class attribute. It’s injecting/overwriting one.

The test is to see if a student has (properly) used an instance attribute for health. If they use a class attribute (or don’t set any attribute for health anywhere at all), the test overrides it and also causes a failure (because the class attribute makes all the instances read the same).

It’s only when a student sets an instance attribute (which will take precedence over the class attribute) that the test will pass - because each instance will be different from the class attribute value.

Sort of klugy, and Isaacs doubling of the principal in a second test might actually help drive home the thing we’re trying to teach here. :slightly_smiling_face:

Nevermind. Had further discussion with Isaac, and I get the scope of the mess. It’s been addressed in this PR, which added a specific test to make sure health was an instance var, and that a Class var for health was disallowed. The former test was cleaned up and stripped of the health attribute, since it was both useless and confusing. :sweat_smile:

1 Like