Check Variable Values

Simple variable value

To check a variable value you need to import the student's code and use dot notation to get the value.
Example, maybe you ask students to assign a variable named num1 the value of 5.
Student Code:
example.py
1
num1 = 5
Copied!
Grading Tests:
1
import unittest
2
​
3
class CodingRoomsUnitTests(unittest.TestCase):
4
​
5
def test_default_case(self):
6
import example
7
self.assertTrue(example.num1 == 5)
8
​
9
if __name__ == '__main__':
10
unittest.main()
Copied!

Number of items in a list

You can do anything you need to with a student's variable value. For example, we can see if a student created a list with at least 3 items using the len() function.
Student Code:
example.py
1
my_list = ["first thing", "second thing", "third thing"]
Copied!
Grading Tests:
1
import unittest
2
​
3
class CodingRoomsUnitTests(unittest.TestCase):
4
​
5
def test_default_case(self):
6
import example
7
self.assertTrue( len(example.my_list) >= 3 )
8
​
9
if __name__ == '__main__':
10
unittest.main()
Copied!
​
Last modified 2mo ago