[testing/python] Support gathering coverage data.

Use the `coverage` tool during tests to gather code coverage data and
conditionally write the results under PULUMI_TEST_COVERAGE_PATH.
This commit is contained in:
Pat Gavlin 2021-10-19 10:57:44 -07:00
parent 960a044abc
commit 96746ddeab
3 changed files with 12 additions and 4 deletions

View file

@ -4,3 +4,4 @@
/env/
/*.egg-info
.venv/
.coverage

View file

@ -50,14 +50,20 @@ test_fast:: $(TEST_ALL_DEPS)
$(GO_TEST) ${PROJECT_PKGS}
pipenv install -e ./env/src
# TODO the ignored test seems to fail in pytest but not unittest. Need to trackdown why
$(RUN_TESTSUITE) python/lib/test pipenv run pytest lib/test --ignore lib/test/automation --ignore lib/test/langhost/resource_thens/test_resource_thens.py
$(RUN_TESTSUITE) python/lib/test/langhost/resource_thens pipenv run python -m unittest lib/test/langhost/resource_thens/test_resource_thens.py
$(RUN_TESTSUITE) python/lib/test pipenv run coverage run -m pytest lib/test --ignore lib/test/automation --ignore lib/test/langhost/resource_thens/test_resource_thens.py
$(RUN_TESTSUITE) python/lib/test/langhost/resource_thens pipenv run coverage run -m unittest lib/test/langhost/resource_thens/test_resource_thens.py
# Using python -m also adds lib/test_with_mocks to sys.path which avoids package resolution issues.
pushd lib/test_with_mocks; $(RUN_TESTSUITE) python/lib/test_with_mocks pipenv run python -m pytest; popd
pushd lib/test_with_mocks; $(RUN_TESTSUITE) python/lib/test_with_mocks pipenv run coverage run -m pytest; popd
ifneq ($(PULUMI_TEST_COVERAGE_PATH),)
if [ -e .coverage ]; then pipenv run coverage xml -o $(PULUMI_TEST_COVERAGE_PATH)/python-fast.xml; fi
endif
test_auto:: test_fast $(TEST_ALL_DEPS)
# Note that this target depends on test-fast for the call to `pipenv run pip install`
$(RUN_TESTSUITE) auto-python pipenv run pytest lib/test/automation
$(RUN_TESTSUITE) auto-python pipenv run coverage run -m pytest lib/test/automation
ifneq ($(PULUMI_TEST_COVERAGE_PATH),)
if [ -e .coverage ]; then pipenv run coverage xml -o $(PULUMI_TEST_COVERAGE_PATH)/python-auto.xml; fi
endif
test_all:: test_fast test_auto

View file

@ -21,3 +21,4 @@ types-six = "*"
types-pyyaml = "*"
types-protobuf = "*"
pytest-asyncio = "*"
coverage = ">=6.0.2"