course-starter-python icon indicating copy to clipboard operation
course-starter-python copied to clipboard

Add local testing capability

Open rahuldave opened this issue 6 years ago • 2 comments

I was looking to test python code locally. There is a conftest.py in the spacy course which could be used as a start, but the testing in this repo does not have that support. So i created a file which has the following hacky code

from wasabi import Printer
import sys

with(open(sys.argv[1])) as fd:
    thesolution = fd.read()
with(open(sys.argv[2])) as fd:
    thetest = fd.read()

__msg__ = Printer()
__solution__ = """{}""".format(thesolution)

exec(thesolution)

exec(thetest)

print(globals().keys())
try:
    test()
except AssertionError as e:
    __msg__.fail(e)

The advantage of this repo's mechanism is that only wasabi needs to be there on the binder server for testing. But if we want to test with data and then need to put the full repo on binder (rather than just a shadow binder repo/branch with maybe a data folder), then additional stuff for pytest does not seem a large imposition?

rahuldave avatar May 23 '19 15:05 rahuldave

One additional thought: pylint/flake8 the student submission. Then "in solution" type tests need not worry about whitespace and stuff.

rahuldave avatar May 23 '19 15:05 rahuldave

Not 100% sure I understand the question – but you should be able to port over the conftest.py from my spaCy course repo and then run pytest. The conftest will take care of putting together the tests using the solution code and test file, and run them accordingly.

One additional thought: pylint/flake8 the student submission. Then "in solution" type tests need not worry about whitespace and stuff.

Yes, I'd use black for that: https://github.com/python/black

ines avatar May 27 '19 13:05 ines