I'm trying to set up a grading script for an intro CS class using unittest
. Essentially, students submit a python file student.py
, which has some number of functions in it that are generally interdependent (meaning that func3()
may use func1()
in it's computations).
I'm writing unit tests for each method by comparing the output of student.func1
to the output of correct.func1
, a method that's known to be the correct implementation (from a file correct.py
).
As an example, say that func2
uses func1
in it's computation.
So, either by default or upon student.func1
failing some test, I want to overwrite student.func1
with correct.func1
, so student.func2
uses a known correct implementation (and therefore isn't just wrong by default). How could I go about doing that? It seems like the setUp()
and tearDown()
are similar to what I want, but I don't know how to "unimport" modules in python, and haven't found any resources about it so far.
I'm interested in both the case where student.py
contains classes, and func1
,func2
are methods of a specific class, and when func1
and func2
are just defined generically within student.py
.