Skip to content

atexit registered functions that print to stdout break test discovery #6581

Closed

Description

When exit handlers that print to standard out are registered using the atexit module, pytest test discovery fails.

Environment data

  • VS Code version: 1.36.1
  • Extension version (available under the Extensions sidebar): 2019.6.24221
  • OS and version: Ubuntu Linux 18.04.2
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.4
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv
  • Relevant/affected Python packages and their versions: pytest
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): Language Server

Expected behaviour

I would expect the relevant tests to be discovered.

Actual behaviour

Test discovery fails because extra text is appended to whatever output is used to store the JSON description of the discovered tests, which subsequently causes a SyntaxError when parsing.

Steps to reproduce:

Allow test discovery to run on the minimal demonstration repository here: https://github.com/joel-wright/pytest-discovery-atexit

Logs

Output for Python Test Log:

python /home/jjw/.vscode/extensions/ms-python.python-2019.6.24221/pythonFiles/testing_tools/run_adapter.py discover pytest -- -s --cache-clear
Test Discovery failed: 
SyntaxError: Unexpected token I in JSON at position 436

Activity

  1. added
    triage-neededNeeds assignment to the proper sub-team
    bugIssue identified by VS Code Team member as probable bug
    on Jul 15, 2019
  2. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Jul 15, 2019
  3. ericsnowcurrently commented on Jul 15, 2019

    @ericsnowcurrently

    That is definitely a function of how our test discovery tooling works. We capture stdout while pytest discovery runs (and only show it on failure) and then write the discovery results to stdout. The best we could do for now is to clear all atexit handlers before the discovery tool finishes. However, doing so would require a bit of a hack (monkey-patching atexit.register()), so it might not be worth it.

    FWIW, we are looking into an alternative approach that would not break with your atexit handler, but that would not be happening any time soon.

  4. joel-wright commented on Jul 16, 2019

    @joel-wright
    Author

    I love the sound of the alternative approach (I discovered this in a relatively large project where test discovery takes multiple minutes).

  5. luabud commented on Sep 17, 2019

    @luabud
    Member

    Closing in favour of #6594.

  6. locked as resolved and limited conversation to collaborators on Sep 24, 2019
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

    area-testingbugIssue identified by VS Code Team member as probable bugregressionBug didn't exist in a previous release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions