From ce14543bc4ab1de29383496b5d71a6b3f50e4519 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 28 Jul 2026 09:51:46 -0700 Subject: [PATCH] [Ellen's Alien Game] Test that an instance variable is used for the health, not a class variable. --- .../concept/ellens-alien-game/classes_test.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/exercises/concept/ellens-alien-game/classes_test.py b/exercises/concept/ellens-alien-game/classes_test.py index 3d2b986be4d..1c5ea27cc9f 100644 --- a/exercises/concept/ellens-alien-game/classes_test.py +++ b/exercises/concept/ellens-alien-game/classes_test.py @@ -7,7 +7,7 @@ except ImportError as import_fail: # pylint: disable=raise-missing-from raise ImportError("\n\nMISSING CLASS --> We tried to import the 'Alien' class from " - "your classes.py file, but could not find it." + "your classes.py file, but could not find it." "Did you misname or forget to create it?") from None try: @@ -144,7 +144,6 @@ def test_alien_class_variable(self): """Test class attribute/variables are identical across instances.""" alien_one, alien_two = Alien(0, 2), Alien(-6, -1) - Alien.health = 6 created_error_message = ('Created two new Aliens and requested the ' 'total_aliens_created attribute for each one. ' @@ -165,6 +164,22 @@ def test_alien_class_variable(self): alien_one.health, msg=health_error_message) + @pytest.mark.task(taskno=6) + def test_alien_health_is_instance_variable(self): + """Test the health is an instance variable and not a class variable.""" + + alien_one, alien_two = Alien(0, 2), Alien(-6, -1) + alien_one.hit() + + error_message = ('Created two new Aliens and called hit() on one of them. ' + f'Received {alien_one.health, alien_two.health} for health, ' + 'but the tests expect them to have different health as ' + 'only one was hit. Are you using a class variable for the health?') + + self.assertNotEqual(alien_two.health, + alien_one.health, + msg=error_message) + @pytest.mark.task(taskno=6) def test_alien_total_aliens_created(self): """Test total_aliens_created class variable increments upon object instantiation."""