question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discover PyTest tests only when necessary

See original GitHub issue

Environment data

  • VS Code version: 1.22.2 (1.22.2) 3aeede733d9a3098f7b4bdc1f66b63b0f48c1ef9
  • Extension version (available under the Extensions sidebar): 2018.3.1
  • OS and version: OSX 10.13.4
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.4
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
  • Relevant/affected Python packages and their versions: n/a

Actual behavior

Test discovery automatically runs after saving edits of a test file.

Although this behavior sounds natural, it causes a spike of energy consumption on every save of an edited test file. One might just want to save it without intending to run test immediately afterwards, e.g. for linting. The fan of my computer starts howling after a few saves.

In OSX activity monitor, energy impact changes from ~1 to ~50 after saving an edited test file, and the energy impact stays around 50 for about 3 seconds. I have 22 tests in the file I saved and 245 tests in total.

Related to issue #1474 and #1132.

Expected behavior

Only run test discovery after giving a command to run or clicking Run Test or Debug Test.

Steps to reproduce:

  1. Edit a test file.
  2. Save the edited test file.
  3. Go to step 1 for a few more times until the fan starts howling. This takes 5 times on my computer.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

============================= test session starts ==============================
platform darwin -- Python 3.6.4, pytest-3.4.2, py-1.5.2, pluggy-0.6.0 -- /XXXXXXXX
cachedir: .pytest_cache
Matplotlib: 2.2.2
Freetype: 2.8.1
rootdir: /XXXXXX, inifile: setup.cfg
plugins: xdist-1.22.2, mpl-0.9, forked-0.2, cov-2.5.1
collecting ... collected 245 items

<<Collected tests>>

========================= no tests ran in 2.89 seconds =========================

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

<<Empty>>

Question

Any pointer on how test discovery works in vscode-python?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brettcannoncommented, Jun 14, 2018
0reactions
brettcannoncommented, May 30, 2018

Providing a feature to disable automatic test discovery seems reasonable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode pytest test discovery fails - python - Stack Overflow
Test files need to be named test_*.py or *_test.py for pytest collection to work. Then run pytest --collect-only at the command line to...
Read more >
Changing standard (Python) test discovery - Pytest
Customizing test collection​​ Since Pytest 2.6, users can prevent pytest from discovering classes that start with Test by setting a boolean __test__ attribute...
Read more >
Testing Python in Visual Studio Code
Test : Run Test at Cursor - Runs only the test method under your cursor in the editor. From the Test Explorer: To...
Read more >
Effective Python Testing With Pytest
Test categorization: pytest can include or exclude tests from particular categories that you define. You can do this with the -m parameter.
Read more >
Test Discovery in Pytest Python - YouTube
Test Discovery with Python Pytest Framework: We will see how pytest does test discovery and selects the tests for execution.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found