Firstly, thank you for reading this post. Hopefully, there is an answer out there in the ether.
I am using unitest and coding rooms to deliver programming courses for users. I am setting up unitest but getting errors. One of which confuses me is an EOF error which is corresponding to an input command.
The input command is outside of the function.
def sleep_calc(user): # ignore this week = user month = week*4 days = month // 24 print("You sleep for " + str(month) + " hours per month") print ("You sleep for "+ str(days)+" whole days per month") return month user = int(input("How many hours per week do you sleep?")) sleep_calc(user) # ignore this
The errors are as follows
File "/usr/lib/python3.8/unittest/loader.py", line 220, in <listcomp> suites = [self.loadTestsFromName(name, module) for name in names] File "/usr/lib/python3.8/unittest/loader.py", line 154, in loadTestsFromName module = __import__(module_name) File "/usercode/coding_rooms_unit_tests.py", line 1, in <module> from main import sleep_calc File "/usercode/main.py", line 9, in <module> user = int(input("How many hours per week do you sleep?")) EOFError: EOF when reading a line
The code in the unitest is as follows:
from main import sleep_calc import unittest class CodingRoomsUnitTests(unittest.TestCase): def setUp(self): # Setup code here (if required, replace the 'pass') pass def tearDown(self): # Teardown code here (if required, replace the 'pass') pass def test_default_case(self): # Your test case logic here (replace the example assertion below) # You may also rename this to any function in the form of 'test_your_test_name(self):' self.assertEquals(sleep_calc(50),200) if __name__ == '__main__': unittest.main()
This is an extremely simple piece of code and so I must be doing something stupid. Thanks in advance
Source: Python Questions