Skip to content

Clean up warnings and log noise from the test suite - #618

Merged
mdickinson merged 6 commits into
mainfrom
fix/615-test-noise-warnings
Aug 5, 2026
Merged

mdickinson merged 6 commits into
mainfrom
fix/615-test-noise-warnings

Conversation

@mdickinson

Copy link
Copy Markdown
Member

Towards #615. This covers the parts of that issue that are unambiguous; the TasksApplication warnings are deliberately left for a follow-up (see the end).

Why this wasn't visible in CI

The noise appears under python -W default -m unittest discover -v envisage — what etstool.py:357 runs. The GitHub Actions jobs run bare python -m pytest, which captures logging and shows it only on failure, and which hides ResourceWarning by default. So the suite has looked clean on GitHub while the EDM runs have not been.

1. ResourceWarning from the resource manager tests

tempfile.py:484: ResourceWarning: Implicitly cleaning up <HTTPError 404: 'No such resource'>

This one is a real defect, not a test artifact. urllib.response.addbase subclasses tempfile._TemporaryFileWrapper, so an HTTPError is a temp-file wrapper and warns if it's collected unclosed. HTTPResourceProtocol.file caught HTTPError and discarded it without closing, which in real use leaves the connection underlying the error response to the garbage collector rather than releasing it promptly.

The fix closes it, with a guard that matters:

Python HTTPError(..., fp=None) .close()
3.8, 3.9 self.fp stays None, file-like bases never initialized KeyError: 'file'
3.10+ self.fp becomes an io.BytesIO works

3.8 is in the test-with-pypi matrix, so an unguarded exc.close() would have broken CI there — and would have been a genuine regression for any caller raising HTTPError with fp=None on those versions. Hence if exc.fp is not None. This also explains why the warning is recent: on 3.8/3.9 the fp=None case produced no wrapper and so no warning at all.

Verified on 3.8, 3.10 and 3.14.

2. PytestCollectionWarning

envisage.tests.test_plugin.TestPlugin matched pytest's Test* collection glob but has an __init__. It's only used for a __repr__ assertion, so it's renamed to SamplePlugin.

3. Log records reaching stderr

Eleven records at WARNING and above, from two call sites:

site records tests
provider_extension_registry.py:85 — unknown extension point 6 5 tests in test_provider_extension_registry (2 via the shared mixin)
plugin.py:287 — logger.exception on a failing contribution 1 test_exception_in_trait_contribution
provider_extension_registry.py:85 — as above 4 4 tests in test_tasks_application — left alone, see below

Every one of these is expected behaviour being deliberately provoked. The review that preceded this PR also found that no test in the suite asserted any log output (assertLogs count: 0), even though these are exactly the WARNING+ messages worth pinning down. So rather than only silencing them:

  • test_exception_in_trait_contribution now asserts the ERROR record and that it carries exc_info — i.e. that logger.exception really attaches the traceback before re-raising.
  • A new test_get_extensions_of_unknown_extension_point asserts the WARNING and the empty return value.
  • The remaining sites provoke the warning only incidentally — including two in ExtensionRegistryTestMixin, which is shared with test_extension_registry.py where the plain ExtensionRegistry is silent for the same input. Wrapping those in assertLogs would either need the mixin to grow a registry-specific hook or would assert a coincidence of the mixin's implementation, so they're suppressed at the level of ProviderExtensionRegistryTestCase.setUp instead, with a comment pointing at the test that does assert the behaviour. assertLogs overrides a logger level set that way, so the assertions above still work.

The tradeoff worth flagging: that suppression is scoped to one logger and one test class, but it would hide an unexpected new WARNING from that logger in those tests. I think that's acceptable now that the behaviour has a dedicated test, but say the word if you'd rather have the mixin hook.

Deliberately not addressed

The four getting extensions of unknown extension point <envisage.ui.tasks.tasks> records from test_tasks_application. TasksApplication declares task_factories = ExtensionPoint(id="envisage.ui.tasks.tasks") (tasks_application.py:85), but the point is only registered by TasksPlugin (tasks_plugin.py:88). The tests build a bare TasksApplication with no plugins, _default_layout_default reads self.task_factories, and the registry warns — which means any real application subclassing TasksApplication without including TasksPlugin gets the same warning at startup. That looks like a wart to fix rather than noise to silence, and it sits next to a related asymmetry (ExtensionRegistry.get_extensions on an unknown id is silent; ProviderExtensionRegistry's warns; set_extensions and remove_extension_point raise UnknownExtensionPoint). Both deserve their own discussion.

Verification

  • pytest: 178 passed, 0 warnings (was 177 passed, 1 warning).
  • python -W default -m unittest discover -t . -s envisage on 3.8, 3.10, 3.14: OK, with only the four deferred tasks records remaining.
  • black --check, isort --check, flake8 clean, using the pinned black ~= 24.3 from style-requirements.txt.

🤖 Generated with Claude Code

mdickinson and others added 5 commits August 5, 2026 13:03
Three independent sources of noise, all visible when the suite is run the
way etstool.py runs it (`python -W default -m unittest discover`), and all
hidden by the bare `python -m pytest` used in the GitHub Actions jobs.

* `HTTPResourceProtocol.file` caught the `HTTPError` raised by `urlopen`
  and discarded it without closing. `urllib.response.addbase` subclasses
  `tempfile._TemporaryFileWrapper`, so an unclosed `HTTPError` emits a
  `ResourceWarning` when collected -- and in real use leaves the
  connection underlying the error response to the garbage collector.
  Close it, guarding against Python 3.8 and 3.9, where an `HTTPError`
  built with `fp=None` doesn't initialize its file-like base classes and
  `close()` raises `KeyError`. (3.8 is in the test matrix.)

* `envisage.tests.test_plugin.TestPlugin` matched pytest's `Test*`
  collection pattern but has an `__init__`, so collecting it raised a
  `PytestCollectionWarning`. Renamed to `SamplePlugin`.

* Eleven log records at `WARNING` and above reached `stderr`, from two
  call sites. Both now have tests that assert them, which is the first
  coverage either has had; the tests that provoked them only incidentally
  suppress them instead.

The four `envisage.ui.tasks.tasks` warnings from the `TasksApplication`
tests are left alone -- those come from building a `TasksApplication`
without the `TasksPlugin` that registers the extension point, which looks
like a genuine wart rather than test noise, and is worth deciding on
separately.

Part of #615.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: the comment only needs to explain why fp is checked
rather than calling close() unconditionally. The rationale for closing
at all is in the changelog entry.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback:

* The NoSuchResourceError raised by HTTPResourceProtocol.file reported
  the address with a "http:://" prefix. Sole occurrence, and no test
  asserts on the message.

* Drop the comment above the assertLogs block in
  test_exception_in_trait_contribution; the assertions say the same thing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reverts the comment to its state on main, byte for byte, so it no longer
appears in the diff at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces warning/log noise when running the Envisage test suite under unittest with default warnings enabled, while also addressing an underlying resource-handling bug in HTTPResourceProtocol.file.

Changes:

  • Close HTTPError responses (when safe) before converting to NoSuchResourceError, avoiding ResourceWarning and fixing the malformed "http:://" URL in the error path.
  • Update tests to (a) assert expected WARNING/ERROR log records via assertLogs and (b) suppress incidental warning noise in the provider extension registry test fixture.
  • Rename a helper plugin class to avoid pytest’s PytestCollectionWarning, and document the fixes in CHANGES.rst.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
envisage/tests/test_provider_extension_registry.py Suppresses incidental warning logs in setup and adds a focused assertLogs test for the unknown-extension-point warning.
envisage/tests/test_plugin.py Renames helper class and adds an assertLogs assertion for the expected logger.exception record when trait contributions fail.
envisage/resource/http_resource_protocol.py Closes HTTPError (guarded for 3.8/3.9 fp=None) before raising NoSuchResourceError, and fixes the URL scheme in the raised message.
CHANGES.rst Records the warning/log-noise cleanup and the HTTP resource protocol fix under the current release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mdickinson
mdickinson merged commit dc5c8dc into main Aug 5, 2026
19 checks passed
@mdickinson
mdickinson deleted the fix/615-test-noise-warnings branch August 5, 2026 12:39
mdickinson added a commit that referenced this pull request Aug 5, 2026
Towards #615. **Stacked on #618** — base is
`fix/615-test-noise-warnings`, so the diff here is just the one commit.
GitHub will retarget this to `main` automatically once #618 merges.

It has to be stacked: `filterwarnings = ['error']` only passes once
#618's two fixes are in, since both the `ResourceWarning` and the
`PytestCollectionWarning` would otherwise fail the suite.

## Why

`pyproject.toml` had no `[tool.pytest.ini_options]` section, so pytest
ran with Python's default warning filters — which ignore
`ResourceWarning` and `ImportWarning` outright. That's precisely why the
`ResourceWarning` fixed in #618 was invisible in the GitHub Actions jobs
while showing up in the EDM runs, which go through `etstool.py` and use
`python -W default -m unittest discover`. Without this, the next warning
we introduce is equally invisible.

## The one escape

TraitsUI emits an `ImportWarning` at import time when numpy is missing,
and numpy isn't in Envisage's dependency closure — the `test-with-pypi`
jobs install only `pytest`, `pyside6` and `.`. So it fires there:

| environment | `pytest` with `filterwarnings = ['error']` and no escape
|
| --- | --- |
| with numpy | 178 passed |
| without numpy | 3 collection errors, all `ImportWarning: ArrayEditor
is not available due to missing numpy` |

The filter matches on the message rather than ignoring `ImportWarning`
as a category, so we keep the protection for any other import warning:

```toml
'ignore:ArrayEditor is not available:ImportWarning',
```

Installing numpy in the test jobs would also have worked, and would
exercise more of TraitsUI — but it adds a test-only dependency to the
matrix to suppress a warning that isn't telling us anything about
Envisage.

## Scope

This governs pytest only. The EDM jobs stay at `-W default`: unittest
has no config-file equivalent, and making that path strict too would
mean putting `-W error` plus escapes into `etstool.py`, which is more
coupling than the benefit justifies. The pytest jobs cover 3.8 and
3.10–3.14, which is enough to catch a new warning.

## Verification

- Full suite passes on Python 3.8, 3.10, 3.12 and 3.14, with and without
numpy: 178 passed each.
- Canary check: a test doing `warnings.warn("canary", UserWarning)` now
**fails**, confirming the config is in effect rather than silently
ignored.
- `black --check`, `isort --check`, `flake8` clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
mdickinson added a commit that referenced this pull request Aug 5, 2026
Closes #615. This removes the last four WARNING-level log records from
the test suite — the ones #618 deliberately deferred.

## The behaviour is fine; the tests were misconfigured

#618 predicted this was "a wart to fix rather than noise to silence",
on the grounds that any application subclassing `TasksApplication`
without `TasksPlugin` warns at startup. Investigating that under #620
turned up the opposite conclusion: `TasksApplication` needs
`TasksPlugin`, so an application without it is misconfigured, and the
warning is doing its job.

The registration path, for the record:

1. `Application.extension_registry` defaults to
   `PluginExtensionRegistry(plugin_manager=self)`.
2. Each plugin is added as a provider;
   `ProviderExtensionRegistry._add_provider_extension_points`
   (`provider_extension_registry.py:159`) stores whatever
   `provider.get_extension_points()` returns.
3. `Plugin.get_extension_points` (`plugin.py:107`) returns the trait
   *type* of every trait marked `__extension_point__=True`.
4. `TasksPlugin.tasks` (`tasks_plugin.py:88`) carries
   `id = "envisage.ui.tasks.tasks"`, which is exactly
   `TasksApplication.TASK_FACTORIES` (`tasks_application.py:48`). Same
   for `task_extensions`.

What makes the dependency easy to miss is that the two sides share no
*name* — the consumer trait is `task_factories`, the provider trait is
`tasks`. Only the id string ties them together.

That the plugin is required is not a novel claim:

* `run_attractor.py:23`, the only complete Tasks example in the tree,
  builds `[CorePlugin(), TasksPlugin(), AttractorsPlugin()]`, and
  `AttractorsPlugin` is a pure contributor — `tasks =
  List(contributes_to="envisage.ui.tasks.tasks")` — relying on
  `TasksPlugin` to have declared the point.
* `docs/source/tasks_user_manual/extensibility.rst:22` has a section
  headed "The Tasks Plugin" describing it as the owner of those
  extension points.

So the pattern of declaring a read-only `ExtensionPoint` trait on a
consumer is not penalised by the warning: it is silent whenever the
companion plugin is present, which supported usage ensures. Verified
both ways — with `TasksPlugin` in the plugin list, no warning and no
ordering hazard; without it, the warning.

## The change

The four noisy tests built a bare `TasksApplication` with no plugins,
`_default_layout_default` read `self.task_factories`, and the registry
warned. All seven constructions in the file now go through a
`create_tasks_application` helper that supplies `TasksPlugin`.

A helper rather than seven copies of `plugins=[TasksPlugin()]`, so the
invariant is stated once in the place that explains why — otherwise it
reads as incidental boilerplate that could be stripped out, bringing
the noise back. Applied to all seven sites, not just the four noisy
ones, so tests added later inherit it.

`test_lifecycle_with_plugin` asserts an exact event sequence; that is
undisturbed, as `TasksPlugin` fires no lifecycle events of its own.

## Not changed

`ProviderExtensionRegistry._get_extensions` keeps the warning, so the
test-side coupling #618 introduced stays correct and needs no edit:
both `test_get_extensions_of_unknown_extension_point` and the `setUp`
logger suppression in `test_provider_extension_registry.py` remain
valid. That suppression is not dead code under this resolution.

The API asymmetry #618 also flagged — `ExtensionRegistry.get_extensions`
silent on an unknown id, `ProviderExtensionRegistry`'s warning,
`set_extensions` and `remove_extension_point` raising
`UnknownExtensionPoint` — is untouched and still deserves its own
discussion.

## Verification

The seven tests in this file are `@requires_gui`, so they skip silently
without a toolkit installed; runs below inject PySide6.

* Before: exactly the four tests named in #620 emitted `getting
  extensions of unknown extension point <envisage.ui.tasks.tasks>`.
* After: zero occurrences anywhere in the suite under
  `--log-cli-level=WARNING`; 178 passed, none skipped, no warnings.
* `black --check`, `isort --check` and `flake8` clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
mdickinson added a commit that referenced this pull request Aug 5, 2026
Closes #616.

Envisage now requires Python 3.10 or later.

## Changes

- `requires-python` is bumped to `>= 3.10`, and the conditional
  `importlib-resources` dependency is dropped. `importlib.resources` has
  provided `files` and `as_file` since 3.9, so the five
  `try`/`except ImportError` import blocks become plain imports.
- `HTTPResourceProtocol.file` closes the caught `HTTPError`
unconditionally again. The `exc.fp is not None` guard added in #618 was
  needed only because `close()` raised `KeyError: 'file'` on 3.8 and 3.9
  when the error had no `fp`; on 3.10+ `self.fp` becomes an `io.BytesIO`
  and `close()` works.
- The EDM runtime lists in `etstool.py` and the two EDM workflows lose
  3.8, leaving 3.11. The `linux_runtime_platform` mapping and the
  `--platform` flag it fed go with it: they existed only to select
  `rh7_x86_64` for the 3.8 runtime, and 3.11 uses EDM's default
  `rh8_x86_64`. The `macos-latest` / 3.8 matrix exclusions go too.
- The `test-with-pypi` matrix drops 3.8, leaving 3.10 through 3.14.
- The stale comment explaining that PySide2 and PyQt5 are unavailable
for
  EDM + Python 3.8 is removed.

The existing `pkg_resources` entry in `CHANGES.rst` described
`importlib-resources` as a backport for Python 3.8, which is no longer
true, so that parenthetical is edited out rather than left to contradict
the new entry.

## Verification

- `pytest`: 171 passed, 7 skipped (no toolkit installed) on both 3.15
and
  a clean 3.10 environment.
- `python -W default -m unittest discover -t . -s envisage`: 178 tests
OK,
  no new warnings.
- `test_resource_manager` under `-W error` on 3.10, to confirm the
  unguarded `exc.close()` is safe there.
- `black --check`, `isort --check`, `flake8` clean.
- `python -m build` plus `twine check --strict` pass; the wheel metadata
  reports `Requires-Python: >=3.10` and no `importlib-resources` in
  `Requires-Dist`.

## One point for review

The EDM matrices are now single-runtime, since 3.8 was the only other
entry. `available_runtimes`, `supported_combinations` and the
`--runtime`
option are all still in place, so adding a runtime is a one-line change.
If EDM offers something newer than 3.11 it would be worth adding here,
rather than leaving the EDM jobs covering a single version.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
mdickinson added a commit that referenced this pull request Aug 5, 2026
A review of the 8.0.0 changelog against `7.0.4..main`. 7.0.4 was tagged
directly on main — `0c02d0b` is both the tag commit and the merge-base —
so
that range is exact. It holds 30 non-merge commits: 11 touching the
library or
packaging, 19 CI and infrastructure.

## The library side was already complete

All eight substantive changes had entries, and both deprecations 7.0.0
promised
to remove in 8.0 (#540, #544) are removed and listed. No
`DeprecationWarning`
remains anywhere in the library, so nothing is left dangling for 9.0.

## References now point at PRs, not issues

The two `Fixes` entries for the `HTTPError` leak cited #615, whose title
is
"Clean up test noise from warnings and WARNING-level log messages". The
leak was
found *via* that cleanup, but a reader following the reference lands on
a
test-hygiene issue rather than a resource-leak fix.

Rather than fix those two in isolation, every reference in the section
now
points at the PR that made the change: #574→#613, #616→#622, #548→#599,
#547→#612, #614→#617, and #615→#618/#619/#621 as appropriate. This also
supplies
the reference the `pkg_resources` entry was missing — #600, the PR,
rather than
#515, the issue.

Two notes:

- The "no longer writes `WARNING`-level log messages" entry cites
**both** #618
and #621. #618 deliberately deferred the four `envisage.ui.tasks.tasks`
records from the `TasksApplication` tests to a follow-up, so the claim
only
  became true once #621 landed.
- Sections for 7.0.4 and earlier are untouched; they already cite PRs.

## CI and build work added

Nineteen PRs had no entry at all, in contrast with 7.0.4, which listed
its
action bumps and copyright-header updates under `Build`. Five new
entries cover
them, aggregated where the work was one theme:

| Entry | PRs |
| --- | --- |
| Trusted publishing (OIDC) and SHA-pinned actions | #604, #608 |
| Copyright end years, and the year-rollover fix to the style check |
#596, #597, #607 |
| GitHub Action bumps | #591, #592, #593, #594, #595, #602, #603, #605,
#606, #609, #610 |
| Pre-release Pythons in the CI matrix | #601, #624 |
| `AGENTS.md` | #598, #626 |

Trusted publishing changes how releases are authenticated, so it seemed
worth
naming rather than folding into the general CI churn.

## Judgment calls worth a second opinion

**The CI matrix entry names no versions.** It reads "now includes
pre-release
Python versions" rather than "3.14, and 3.15 pre-releases". Naming them
is more
informative, but in a section whose `Removals` entry deliberately gives
no
upper bound on supported Pythons, a `Build` line ending in "3.15"
invites
exactly the reading that bound was left out to avoid. Easy to change if
you'd
rather have the numbers.

**No upper bound on Python versions.** Considered and rejected: it means
churn
on every Python release, and forwards compatibility is the reasonable
default
expectation for a package that runs warning-free on the current version.

**Deliberate omissions.** #626's other cleanups — an `IServiceRegistry`
docstring, the legacy examples README, dead Traits<6.0 test code —
change
nothing for users. There's no `Documentation` section because the doc
edits in
#599 are just the egg-manager material going away with the classes,
already
covered by the `Removals` entry. And `CorePlugin` gaining its own
`stop()` to
unregister service offers is an implementation move; the #617 entry
already
notes that `PluginActivator` no longer calls
`register_services`/`unregister_services`, which is the part a
downstream
`Plugin` subclass would notice.

## Left to the release PR

The `Released:` date line, an introductory paragraph, a "Thanks to:"
list, and
the `version = '7.0.4'` still in `pyproject.toml`. The date isn't
settled yet.

## Verification

`CHANGES.rst` parses under docutils with no warnings at report level 2
or above,
and all lines stay within 79 characters. Changelog only — no code
touched.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants