Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mabruzzo
Copy link
Collaborator

This PR lightly refactors some of the answer test functionality to make use of pytest machinery. The key point here is that you can now pass a command line flag --answer-store instead of modifying the GENERATE_PYGRACKLE_TEST_RESULTS environment variable. The 2 primary command line flags are named after the flags used by yt.

I would ultimately like to move more towards these command line flags (and maybe even eventually remove the GENERATE_PYGRACKLE_TEST_RESULTS variable). But we can return to that in the future

@mabruzzo mabruzzo added testing test suite, regression tests, ci infrastructure refactor internal reorganization or code simplification with no behavior changes and removed refactor internal reorganization or code simplification with no behavior changes labels Sep 23, 2024
@mabruzzo mabruzzo force-pushed the answer-test-refactor branch from 35e80ff to 4a9c739 Compare September 24, 2024 11:12
@brittonsmith
Copy link
Contributor

I haven't had time to look this over properly yet, but I'm in favor of the concept of this PR. The main thing I want to say now is I don't think we need to retain the old system given that it was only recently introduced. For simplicity, I'd say let's go ahead and remove the environment variable system now.

Copy link
Contributor

@brittonsmith brittonsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. I had just a few comments. I'm still also in favor of removing the environment variable system altogether before merging.

^^^^^^^^^^^^^^^^^^^^^^^^
To run the test-suite without any answer tests, invoke ``py.test`` with the ``--answer-skip`` flag.

To control the location of the directory where the test answers are save, you can invoke ``py.test`` with the ``--local-dir`` flag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To control the location of the directory where the test answers are save, you can invoke ``py.test`` with the ``--local-dir`` flag
To control the location of the directory where the test answers are saved, you can invoke ``py.test`` with the ``--local-dir`` flag

# this hook is used to add more command line flags to the pytest launcher
def pytest_addoption(parser):
parser.addoption(
"--answer-skip",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to only have --answer-store since they do the same thing. Both variables are mentioned above for running tests without answer testing. I think it just adds confusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 -local-dir a required argument to run the answer tests?1 In that picture:

  • pytest grackle/src/python wouldn't run all non-answer tests
  • pytest grackle/src/python --answer-store --local-dir=path/to/answers would store answers (and run all non-answer tests)
  • pytest grackle/src/python --answer-store would abort with an error.
  • pytest grackle/src/python --local-dir=path/to/answers would check answer-test answers (and run all non-answer tests)

To be clear, I'm definitely not wedded to this idea. I'm happy to move forward and just simply remove --answer-skip. In fact, I'll just plan to go ahead and simply remove --answer-store without any sort of replacement unless I hear that you like this alternative idea.

Footnotes

  1. If we went that route, maybe we should rename --local-dir to --answer-dir

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I like this. I also really like changing --local-dir to --answer-dir. "local-dir" can be interpreted in a variety of different ways, but to me "answer-dir" can only mean "the answers are/go here." If we do this, the meaning of "will not run answer tests" needs clarifying to either mean 1) the tests won't run at all or 2) the code to generate the answers will be run, but no comparison will happen.

"""
Tests for the local functions.
"""

n_input_sets = 10
seed = 21062024
digits = 12
test_file = os.path.join(test_answers_dir, "local_function_tests.json")
test_file_basename = "local_function_tests.json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we no longer storing the json file in the answer test directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do still do put the json file in the answer-test-directory. The line that you highlighted has changed to now just specifies the basename of the test-file.

On line 192 we infer the full path to the test-file with

    test_file = os.path.join(answertestspec.answer_dir, self.test_file_basename)

and I replaced all references to self.test_file to now access test_file.

The key change here is that I removed the global test_answers_dir variable. Now, the answer test directory is encoded in the value returned by the answertestspec fixture. (It is accessed via answertestspec.answer_dir).

Would it help if I added an explanatory comment just before the line that you highlighted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for clarifying. The issue was mine. I think I transposed test_file with test_file_basename in my head and could no longer find the corresponding instance of os.path.join.

@mabruzzo
Copy link
Collaborator Author

mabruzzo commented Oct 9, 2024

This looks fine to me. I had just a few comments. I'm still also in favor of removing the environment variable system altogether before merging.

I can give that a try later today. I'm all for this too (it's just going to cause all of the answer tests to fail until after we update the gold standard)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing test suite, regression tests, ci infrastructure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants