Skip to content

Add a framework for functional tests like in pylint - #3484

Draft
Pierre-Sassoulas wants to merge 2 commits into
pylint-dev:mainfrom
Pierre-Sassoulas:functional-tests
Draft

Pierre-Sassoulas wants to merge 2 commits into
pylint-dev:mainfrom
Pierre-Sassoulas:functional-tests

Conversation

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

Type of Changes

Type
✓ ✨ New feature

Description

Add functional tests like in pylint to reduce the boilerplate needed for astroid's test.

@Pierre-Sassoulas Pierre-Sassoulas added Maintenance Discussion or action around maintaining astroid or the dev workflow Skip news 🔇 This change does not require a changelog entry labels Nov 23, 2026
@codspeed

codspeed Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

Caution

Benchmarks ran in several CI workflows

Your benchmarks ran in several CI workflows on this commit, which isn't supported. Move all your benchmark jobs into a single workflow for CodSpeed to work properly.

Learn more about sharding benchmarks

✅ 3 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing Pierre-Sassoulas:functional-tests (bd62fe5) with main (4bd783b)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

A file under tests/functional is parsed by astroid and its comments
say what must be found for the node on their line:

    Cat().speak()  # inferred: Const('meow')
    x = foo(1, 2)  # value.args[0].inferred: Const(1)

The comment is a path from the node (attributes, indexes, calls with
plain arguments) followed by what it leads to. ``pytest --remaster``
fills in or updates the answers, to be reviewed in the diff.

Like in pylint's functional tests, a ``.rc`` file gates a whole file
(min_pyver, max_pyver, requires, ...), a condition gates one
expectation (``# >=3.14: inferred: ...``) and ``# +1:`` puts an
expectation on the line above the code it is about.

The order of inferred results is not asserted: they are sorted before
being compared. A container is written with its elements.

The comments are read and rewritten by check_inline, from
pytest-remaster 0.2.
The unit tests that only parsed a snippet and asserted on its nodes
become 726 annotated files under tests/functional, one directory per
test module they come from.

Parametrized tests, tests without a snippet and the line and column
checks (tests/test_nodes_lineno.py, tests/test_nodes_position.py)
stay unit tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Maintenance Discussion or action around maintaining astroid or the dev workflow Skip news 🔇 This change does not require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant