Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Conversation

@codesue
Copy link
Contributor

@codesue codesue commented Dec 2, 2022

What does this pull request do?

This pull request enables running tests with pytest and unittest as the test runners. Previously, running tests with these runners raised the following error:

absl.flags._exceptions.UnparsedFlagAccessError: Trying to access flag --test_tmpdir before flags were parsed.

This happened because the absl flags were only being parsed when running the modules directly. With this change, flags are manually parsed and use default values if the modules aren't run directly, as is the case when using pyttest and unittest. See the absl-py flags documentation for a more detailed explanation.

How did you test this change?

pytest

Ran pytest model_card_toolkit. Abridged summary:

================================ test session starts =================================
platform darwin -- Python 3.8.13, pytest-7.2.0, pluggy-1.0.0
rootdir: /Users/sue/workspace/oss/mct-dev/model-card-toolkit
plugins: anyio-3.6.2
collected 86 items                                                                   

model_card_toolkit/core_test.py ..................                             [ 20%]
model_card_toolkit/model_card_test.py ................                         [ 39%]
model_card_toolkit/documentation/examples/cats_vs_dogs_test.py .               [ 40%]
model_card_toolkit/tfx/artifact_test.py .                                      [ 41%]
model_card_toolkit/tfx/component_test.py ..                                    [ 44%]
model_card_toolkit/tfx/executor_test.py .....                                  [ 50%]
model_card_toolkit/utils/graphics_test.py .........                            [ 60%]
model_card_toolkit/utils/json_util_test.py ...                                 [ 63%]
model_card_toolkit/utils/tfx_util_test.py .....................                [ 88%]
model_card_toolkit/utils/validation_test.py .......                            [ 96%]
model_card_toolkit/utils/testdata/testdata_utils_test.py ...                   [100%]

===================== 86 passed, 11 warnings in 87.51s (0:01:27) =====================

unittest

Couldn't figure out the right pattern to discover all tests, so I only tested the problematic modules.

Ran python -m unittest model_card_toolkit/core_test.py:

Ran 18 tests in 68.112s

OK

Ran python -m unittest model_card_toolkit/utils/testdata/tfxtest.py:

Ran 1 test in 0.005s

OK

How did you document this change?

N/A

Before submitting

Before submitting a pull request, please be sure to do the following:

  • Read the How to Contribute guide if this is your first contribution.
  • Open an issue or discussion topic to discuss this change. (Discussed over video chat.)
  • Write new tests if applicable.
  • Update documentation if applicable.

@codesue codesue closed this Dec 3, 2022
@codesue codesue deleted the codesue/enable-pytest-as-runner branch December 3, 2022 00:50
@codesue codesue removed this from the Lower the barrier to contributing milestone Dec 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant