I'm trying to write a command line tutorial to help users learn Pytest (as I'm learning it myself) and digital logic simultaneously. I need to figure out a good way of testing test files that a user will write to ensure their test functions work as they should.
The learner will have the task of writing test files, which test functions they're also tasked to write. By way of example, the goal would be for them to end up writing the following (or something equivalent based on test criteria):
test_not.py
solutions_path='./solutions/'
import sys
sys.path.append(solutions_path)
import re
import _not from _not
def test_allowed():
f = open(solutions_path+"_not.py", "r")
text=f.read()
print(text)
assert not (bool(re.search("\snot", text)))
def test_not():
assert (_not(True)==(not True)) and (_not(False)==(not False))
solutions/_not.py
def _not(a):
if a:
return False
return True
So what I need to figure out is an effective way of testing the file test_not.py such that it can be determined to pass a set of requirements like the following:
- create a file called
test_not.py. This will test an alternate version of thenotoperation that you will write yourself. - write a test that fails if the word
notappears in the file to be tested. - write a test that confirms that function called
_notbehaves the same as the standardnotused by Python.
I'm new to Pytest myself and I'm not sure what options are available to me. Can anyone think of a way to do this?
Aucun commentaire:
Enregistrer un commentaire