-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Answer test refactor #245
base: main
Are you sure you want to change the base?
Answer test refactor #245
Changes from all commits
f65f4bb
eee0efc
85fe2a4
e250b8c
0b9210f
e484a3f
4a9c739
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# this defines some basic utilities shared among all of the tests | ||
# | ||
# DO NOT import pygrackle into global scope in this file (or in any file | ||
# imported by this file). Some tests need to be runable without installing | ||
# pygrackle | ||
|
||
import os | ||
from typing import NamedTuple | ||
|
||
import pytest | ||
|
||
|
||
# this hook is used to add more command line flags to the pytest launcher | ||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--answer-skip", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to only have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure I can do that! I'm just spitballing here, but I think it could still be nice (but definitely not essential) to support disabling all of the answer-tests. If we aren't worried about backwards compatability, what if we made
To be clear, I'm definitely not wedded to this idea. I'm happy to move forward and just simply remove Footnotes
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I like this. I also really like changing |
||
action="store_true", | ||
help="Indicates that we should skip all answer tests.", | ||
) | ||
parser.addoption( | ||
"--answer-store", | ||
action="store_true", | ||
help="Indicates that we should generate test results.", | ||
) | ||
|
||
# in the future, I think we should revisit the default behavior when this | ||
# is omitted. Instead of providing a default location, I think we should | ||
# just skip all answer tests (and maybe raise an error if the | ||
# --answer-store flag is provided without this flag) | ||
parser.addoption( | ||
"--local-dir", | ||
action="store", | ||
default=os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), "test_answers" | ||
), | ||
help="Path to directory where answers are/will be stored.", | ||
) | ||
|
||
|
||
class AnswerTestSpec(NamedTuple): | ||
generate_answers: bool | ||
answer_dir: str | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def answertestspec(request): | ||
""" | ||
Return an object specifying all user-specified directives regarding | ||
answer tests (whether to run them and where to store/find results) | ||
""" | ||
if request.config.getoption("--answer-skip"): | ||
if request.config.getoption("--answer-store"): | ||
raise RuntimeError( | ||
"It is an error to specify both --answer-skip and --answer-store" | ||
) | ||
pytest.skip("--answer-skip was specified") | ||
|
||
generate_answers = ( | ||
request.config.getoption("--answer-store") | ||
or int(os.environ.get("GENERATE_PYGRACKLE_TEST_RESULTS", 0)) == 1 | ||
) | ||
answer_dir = request.config.getoption("--local-dir") | ||
|
||
if (not os.path.isdir(answer_dir)) and (not generate_answers): | ||
pytest.skip(f"the directory of test answers can't be found, {answer_dir}") | ||
os.makedirs(answer_dir, exist_ok=True) | ||
|
||
return AnswerTestSpec(generate_answers=generate_answers, answer_dir=answer_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.