Skip to content

pytest hook reference - pytest_cmdline_preparse deprecated #3022

Closed

Description

@buddhadev

pytest documentation mentions that pytest_cmdline_preparse hook will be deprecated.

Reference:

https://docs.pytest.org/en/latest/writing_plugins.html#_pytest.hookspec.pytest_cmdline_preparse

Question

What is the alternative to this hook moving forward?

Activity

  1. added
    type: docs
    on Dec 12, 2017
  2. pytestbot commented on Dec 12, 2017

    @pytestbot
    Contributor

    GitMate.io thinks the contributor most likely able to help you is @nicoddemus.

  3. nicoddemus commented on Dec 12, 2017

    @nicoddemus
    Member

    I don't know so I dug around a little, it seems that deprecation was introduced in db6f347 with the introduction of pytest_load_initial_conftests, so I would recommend using that instead.

  4. buddhadev commented on Dec 12, 2017

    @buddhadev
    Author

    Thanks @nicoddemus !

  5. added a commit that references this issue on Dec 12, 2017
    7b5d4d0
  6. Sup3rGeo commented on Apr 19, 2018

    @Sup3rGeo
    Member

    @nicoddemus the documentation uses pytest_cmdline_preparse in one example:

    https://docs.pytest.org/en/latest/example/simple.html#dynamically-adding-command-line-options

    Should it be updated to use pytest_load_initial_conftests ?

  7. nicoddemus commented on Apr 20, 2018

    @nicoddemus
    Member

    Definitely @Sup3rGeo, thanks for noticing. Opened #3417 for it.

  8. apteryks commented on Sep 30, 2021

    @apteryks

    Unfortunately pytest_load_initial_conftests doesn't work from inside conftest.py, so it's not an exact replacement.

  9. jxramos commented on Aug 11, 2025

    @jxramos
    Contributor

    this is tricky, I'm leaning on pytest_cmdline_preparse to inject the bazel test target as a suffix to the --log-file.

    When I make that modification in pytest_cmdline_preparse the value is reflected before the log is opened and I see the correct value reflected in the pytest_report_header I added to report the --log-file value #13635 (comment).

    When I pivot the implementation over to using pytest_load_initial_conftests the ordering must be off or something because the --log-file value still assumes the value passed at the command line shell for the pytest invocation with the suffixing not taking effect.

  10. jxramos commented on Aug 15, 2025

    @jxramos
    Contributor

    noting for posterity, the actual deletion of the pytest_cmdline_preparse hook is found in this commit
    f4e7b0d#diff-3bcca5362f4ed2c327bb6e465f6f53d516b8bc5561d3ae72a1519666700511a3

    This commit landed on Jan 2, 2024, and was released in pytest version 8.1.0

  11. nicoddemus commented on Aug 16, 2025

    @nicoddemus
    Member

    @jxramos thanks.

    It was deprecated in 7.0.0rc1, but we did not add the respective changelog entry about its removal in 8.1.0.

    Would you like to contribute a PR amending the changelog?

  12. jxramos commented on Jan 18, 2026

    @jxramos
    Contributor

    @nicoddemus , ok finally getting back to this, got a PR out on the topic found here #14124.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: docs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions