Skip to main content

Testing plugin for funcnodes

Project description

pytest-funcnodes

pytest_funcnodes is the maintained pytest plugin for FuncNodes modules. It replaces the legacy TestAllNodesBase harness by supplying decorators, fixtures, and coverage helpers that keep the runtime isolated and guarantee every node is exercised.

Key Features

  • @pytest_funcnodes.nodetest Marks async node tests, injects pytest.mark.asyncio, and records which node classes were covered. Every test that executes a node must use this decorator so the plugin can reset registries and track coverage.

  • @pytest_funcnodes.funcnodes_test Wraps sync or async tests that interact with funcnodes_core / funcnodes state (loading shelves, running flows, tweaking config). It toggles the same isolated test_context used for node tests, disabling file loggers and pointing configs at a per-test temp directory.

  • Autouse fixtures & CLI flag The plugin ships nodetest_setup_teardown / funcnodes_test_setup_teardown fixtures plus --nodetests-only, letting you run just node suites while keeping isolation guarantees.

  • Coverage helper pytest_funcnodes.all_nodes_tested(all_nodes, shelf, ignore=...) flattens shelves and asserts that every exported node class was covered by a @nodetest.

Installation

uv add pytest-funcnodes
# or
pip install pytest_funcnodes

Usage

1. Mark node tests

import pytest_funcnodes
import funcnodes as fn

@fn.NodeDecorator("demo.concat")
def concat(a: str, b: str) -> str:
    return a + b

@pytest_funcnodes.nodetest(concat)
async def test_concat():
    node = concat()
    node["a"] = "foo"
    node["b"] = "bar"
    await node
    assert node["out"].value == "foobar"

2. Mark runtime/integration tests

import pytest_funcnodes
from funcnodes_core import config as fnconfig

@pytest_funcnodes.funcnodes_test
def test_config_uses_temp_dir():
    cfg_dir = fnconfig.get_config_dir()
    assert cfg_dir.name.startswith("funcnodes_test_")

3. Enforce shelf coverage

from pytest_funcnodes import all_nodes_tested
import funcnodes_basic as fnmodule

def test_all_nodes_tested(all_nodes):
    all_nodes_tested(all_nodes, fnmodule.NODE_SHELF, ignore=[])

This assertion fails with a list of missing node classes if any exported node lacks a @nodetest.

4. CLI workflow

  • pytest --nodetests-only filters the run down to node suites.
  • The session fixture prints Session fixture setup/teardown, confirming the plugin activated.
  • No manual calls to funcnodes_core.testing.setup() / teardown() are required—the fixtures enter and exit test_context automatically.

Runtime Isolation Details

test_context (see pytest_funcnodes/testingsystem.py) rewrites the FuncNodes config directory into a temp folder per PID, clears leftovers between tests, disables file handlers, upgrades selected warnings (e.g., FuncNodesDeprecationWarning) to errors, and removes the temp directory on exit. This means:

  • Tests never leak global registry state (funcnodes_core.node.REGISTERED_NODES is cleared after each run).
  • File logs stay inside the temp dir and are removed after teardown.
  • Fail-fast behavior surfaces deprecated APIs that still fire warnings.

Always prefer the provided decorators over manual setup so these safeguards remain effective.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_funcnodes-1.0.0a1.tar.gz (46.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_funcnodes-1.0.0a1-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_funcnodes-1.0.0a1.tar.gz.

File metadata

  • Download URL: pytest_funcnodes-1.0.0a1.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_funcnodes-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 8092c46c5b75eab76563597f0a0c47fe130abef9eb4b432507c27eb71de9b228
MD5 cae06e9d81ca0645c5ad6897f6db81cc
BLAKE2b-256 95fad7e62963183baf0dde24cf4cdd9ea4eef59f2d27d8469f0a12a2de6c1a33

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_funcnodes-1.0.0a1.tar.gz:

Publisher: version_publish_main.yml on Linkdlab/funcnodes_pytest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_funcnodes-1.0.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_funcnodes-1.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 0736ddcb006e26041bd3935657c0215ca894ee9e9651abe52e98648ffc89ad58
MD5 59f1ea600ef082bebd4fd1435b36cfe7
BLAKE2b-256 b1c551964a74df7cc63254f384fec354a7abbe0cbdc71838206be820c4e17192

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_funcnodes-1.0.0a1-py3-none-any.whl:

Publisher: version_publish_main.yml on Linkdlab/funcnodes_pytest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page