polite-angle-82480
04/17/2023, 1:35 AMPythonDistribution
I also need to manually specify its address
property since the plugin code I’m testing expects the mock to have it:
python_distributions = Mock(PythonDistribution)
python_distributions.address = Address
When trying to correctly construct objects from the various pants-native classes (e.g. PythonDistribution
, Dependents
, Address
, etc) I often run into errors and then need much more boilerplate code to create. Thoughts?enough-analyst-54434
04/17/2023, 1:40 AM$ find -name "*_test.py" | wc -l
428
And, as a percentage, it uses mocking in less than 3% of test files:
$ find -name "*_test.py" | xargs git grep unittest | grep mock | grep import | cut -d: -f1
build-support/bin/generate_json_schema_test.py
src/python/pants/backend/javascript/subsystems/nodejs_test.py
src/python/pants/backend/python/goals/pytest_runner_integration_test.py
src/python/pants/backend/python/util_rules/pex_from_targets_test.py
src/python/pants/base/deprecated_test.py
src/python/pants/base/exception_sink_test.py
src/python/pants/core/goals/generate_lockfiles_test.py
src/python/pants/engine/internals/platform_rules_test.py
src/python/pants/jvm/resolve/coursier_fetch_filter_test.py
src/python/pants/option/option_types_test.py
src/python/pants/option/options_test.py
src/python/pants/util/dirutil_test.py
In other words, by example, you probably shouldn't need to use mocking at all. Have you looked at how Pants tests itself yet?polite-angle-82480
04/17/2023, 1:42 AMMock(
and saw that there were very few mocks. I’m looking through the various tests in the pants repo now, thanks