zopefoundation / zope.testrunner

This package provides a flexible test runner with layer support.
https://zopetestrunner.readthedocs.io/
Other
2 stars 23 forks source link

testing: ResourceWarnings #144

Closed mtelka closed 1 year ago

mtelka commented 1 year ago

BUG/PROBLEM REPORT / FEATURE REQUEST

There are few ResourceWarnings printed during testing.

What I did:

/usr/bin/tox-3.7  --current-env --no-provision --recreate -e py37 -- -vv

What I expect to happen:

No ResourceWarnings printed.

What actually happened:

...
 $(PYTHON_DIR)/vendor-packages/zope/testrunner/tests/testrunner-new-threads.rst
 TestTrace (zope.testrunner.coverage)
 normalize_package (zope.testrunner.options)
$(PYTHON_DIR)/subprocess.py:883: ResourceWarning: subprocess 23107 is still running
  ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
 StartUpFailure (zope.testrunner.find)
...
 test_tests_from_suite_records_duplicate_test_ids (zope.testrunner.tests.test_find.TestUniqueness)
$(PYTHON_DIR)/vendor-packages/zope/testrunner/tests/testrunner-ex/gc-after-test.py:61: ResourceWarning: not closed
  warn(ResourceWarning("not closed"))
$(PYTHON_DIR)/vendor-packages/zope/testrunner/tests/testrunner-ex/gc-after-test.py:61: ResourceWarning: not closed
  warn(ResourceWarning("not closed"))
$(PYTHON_DIR)/vendor-packages/zope/testrunner/tests/testrunner-ex/gc-after-test.py:61: ResourceWarning: not closed
  warn(ResourceWarning("not closed"))
...

What version of Python and Zope/Addons I am using:

OS: OpenIndiana Python: 3.7.16 & 3.9.16 zope.testrunner: 5.6

d-maurer commented 1 year ago

Marcel Telka wrote at 2023-2-1 05:37 -0800:

There are few ResourceWarnings printed during testing. ... $(PYTHON_DIR)/vendor-packages/zope/testrunner/tests/testrunner-ex/gc-after-test.py:61: ResourceWarning: not closed warn(ResourceWarning("not closed")) $(PYTHON_DIR)/vendor-packages/zope/testrunner/tests/testrunner-ex/gc-after-test.py:61: ResourceWarning: not closed warn(ResourceWarning("not closed")) $(PYTHON_DIR)/vendor-packages/zope/testrunner/tests/testrunner-ex/gc-after-test.py:61: ResourceWarning: not closed warn(ResourceWarning("not closed"))

The ResourceWwarnings from the gc-after-test tests are there by purpose: The option --gc-after-test has the purpose to associate the warning with the test responsible for the resource leakage. Without this option, some resource leaks are only detected during the next garbage collection -- potentially far away from the responsible test. In order to verify that the leaks are reported for the corresponding test, the gc-after-test tests create intensionally resource leaks.

Unfortunately, it is very difficult to prevent the resource warnings to be output to stderr. If you have an idea, a PR is welcome.

icemac commented 1 year ago

In https://github.com/zopefoundation/zope.testrunner/commit/f10acf0679271f3e6b72a4e286cdf7624bcd3b9a I am improving the error message of the resource warning. It seems that this is the best we can do for now.