Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: use pytest to collect and execute test fillers #116

Conversation

danceratopz
Copy link
Member

@danceratopz danceratopz commented Apr 26, 2023

This PR (work in progress) ports the test-filling process implemented in the custom tf framework to the pytest framework. Pytest becomes responsible for collecting fillers (test functions) and managing their execution to generate fixtures from the spec defined within them.

This is achieved by:

  1. Defining a test spec in a test function (as before),
  2. Storing them from within the test function in a test-function-scoped helper pyest fixture, and,
  3. Executing the stored TestSpec/filler (and writing the fixtures) in pytest's pytest_runtest_call() hook.

Pytest is a widely used Python framework and offers several advantages out-of-the-box:

  • Separation of test filler collection and execution; pytest --collect-only can be used to explore which fillers are available. Use pytest --collect-only -v for a list with docstrings.
  • Pytest will continue execution if a filler fails (tf stops upon error).
  • Parametrization of tests (the ethereum fork is also parametrized) which gives more context to test filler errors.
  • Easier filtering and specification of a subset of test fillers during development (e.g. pytest -k warm_coinbase or pytest -k Shanghai).
  • Easily drop into the debugger via pytest --pdb upon test filler error.
  • pytest-xdist can be used to execute test fillers concurrently.

Some demos and screenshots of pytest with execution-spec-tests can be found here (but note that these were generated from a different and now very out-of-date branch).

Quick start for working with this branch:

git clone git@github.com:danceratopz/execution-spec-tests.git
git checkout feature/use-pytest-to-collect-and-hydrate-test-fillers
python -m venv ./venv
source venv/bin/activate
pip install -e .
pytest --collect-only
pytest -v
# or run a newly ported filler explicitly
pytest -v fillers/eips/eip3651.py

To do list for framework related tasks:

To do list for porting test fillers to pytest format:

@lightclient
Copy link
Member

I think this is a great idea! My only request is to try and keep the core dev who doesn't write python on a regular basis in the back of your mind as you develop the filler interface. One problem with the retesteth fillers IMO is that they became a DSL that only those who were regularly writing them could use / understand. One goal of this project should be for core devs to i) come in and fairly easily understand what is and isn't being tested and ii) write tests for a proposal if your team is busy with other things or their proposal isn't yet a priority.

danceratopz and others added 25 commits May 25, 2023 23:55
Additionally test that the contract call fails if call_exact_gas - 1 is specified instead of call_exact_gas.
This is to try and avoid confusion when running experimental fillers for upcoming protocol upgrades.
danceratopz and others added 23 commits June 7, 2023 16:49
Also change the tf entry point to help the user get help with fill.
This removes the latest_fork_resolver. Deployed/developement forks are managed instead by an is_deployed() helper method to differentiate between deployed forks and forks under development. The user of ethereum_test_forks.helpers must now specify explicitly which forks are relevant. Currently, the main user of helpers is the src/pytest_plugins/forks plugin.
This change keeps a consistent interface with the get_forks()/get_deployed_forks()/get_development_forks() helpers
…cifying-fork-validity-for-tests

pytest: add markers specifying test fork validity + framework cleanup
@danceratopz danceratopz marked this pull request as ready for review June 7, 2023 20:29
Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

LGTM!

@spencer-tb
Copy link
Collaborator

LGTM :D

@danceratopz danceratopz merged commit ae5df2f into ethereum:main Jun 7, 2023
2 checks passed
@danceratopz danceratopz deleted the feature/use-pytest-to-collect-and-hydrate-test-fillers-v2 branch June 23, 2023 06:40
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.

None yet

4 participants