tfx icon indicating copy to clipboard operation
tfx copied to clipboard

Tests reference `__main__`

Open smokestacklightnin opened this issue 1 year ago • 0 comments

System information

  • Have I specified the code to reproduce the issue: yes
  • Environment in which the code is executed: Linux
  • TensorFlow version:
  • TFX Version: Latest
  • Python version: 3.9, 3.10
  • Python dependencies (from pip freeze output):

Some of the tests reference objects as part of their respective __main__ modules. After PR #6889, running those tests with pytest causes test failures. As a result, those tests were xfailed.

The list of files using __main__ are as follow:

$ find -name "*test.py" -exec grep -n -F "__main__" {} +
./types/standard_artifacts_test.py:72:    ' \"__main__\", \"__tfx_object_type__\": '
./dsl/component/experimental/decorators_test.py:657:        test_pipeline.components[0].type, '__main__.injector_1_with_annotation'
./dsl/component/experimental/decorators_test.py:663:        '__main__.simple_component_with_annotation',
./dsl/component/experimental/decorators_test.py:668:        test_pipeline.components[2].type, '__main__.verify_with_annotation'
./dsl/component/experimental/decorators_typeddict_test.py:678:        test_pipeline.components[0].type, '__main__.injector_1_with_annotation'
./dsl/component/experimental/decorators_typeddict_test.py:685:        '__main__.simple_component_with_annotation',
./dsl/component/experimental/decorators_typeddict_test.py:691:        test_pipeline.components[2].type, '__main__.verify_with_annotation'
./dsl/components/base/executor_spec_test.py:51:        class_path: "__main__._DummyExecutor"
./dsl/components/base/executor_spec_test.py:67:            class_path: "__main__._DummyExecutor"
./orchestration/portable/input_resolution/input_graph_resolver_test.py:497:            op_type: "__main__.RenameStrategy"
./utils/json_utils_test.py:48:            '{"__class__": "_DefaultJsonableObject", "__module__": "__main__",'
./utils/json_utils_test.py:70:            '{"__class__": "_DefaultJsonableObject", "__module__": "__main__",'
./utils/json_utils_test.py:72:            ' "_DefaultJsonableObject", "__module__": "__main__",'
./utils/json_utils_test.py:96:            '{"__class__": "_DefaultJsonableObject", "__module__": "__main__",'
./utils/json_utils_test.py:98:            ' "_DefaultJsonableObject", "__module__": "__main__",'
./utils/json_utils_test.py:115:            '{"__class__": "_DefaultJsonableObject", "__module__": "__main__",'
./utils/json_utils_test.py:130:            '{"__class__": "_DefaultJsonableObject", "__module__": "__main__",'

The list of tests as described is small enough that someone can simply change the module paths from __main__ to the appropriate paths. This will likely fix the tests and allow them to have the xfail mark removed.

It is also worth noting that checking classname of objects like this is brittle and prone to breakage if a different invocation is used or if there is a refactor.

smokestacklightnin avatar Oct 16 '24 01:10 smokestacklightnin