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.

Pytest test discovery confused by packages

See original GitHub issue

Environment data

  • VS Code version: 1.30.2
  • Extension version (available under the Extensions sidebar): 2018.12.1
  • Relevant/affected Python packages and their versions: pytest 3.9.1

Expected behaviour

Tests are discovered correctly

Actual behaviour

Any package causes subsequently discovered tests to be considered IN the package

Steps to reproduce:

  1. Create a tests folder
  2. Create test/testa/test_first.py test/testc/test_last.py with regular python tests (any function will suffice)
  3. Create test/testb/init.py and test/testb/test_second.py with a python test function
  4. Run discover tests

Logs

Example pytest output:

============================= test session starts ==============================
platform linux -- Python 3.6.0, pytest-3.9.1, py-1.7.0, pluggy-0.8.0
Using --randomly-seed=1547049040
rootdir: /home/alex/git/HP-DLF, inifile:
plugins: repeat-0.7.0, randomly-1.2.3, profiling-1.3.0, cov-2.6.0, console-scripts-0.1.7, nbval-0.9.1
collected 3 items
<Module 'test/testa/test_first.py'>
  <Function 'test_foo'>
<Package '/home/.../test/testb'>
  <Module 'test_second.py'>
    <Function 'test_foo'>
<Module 'test/testc/test_last.py'>
  <Function 'test_foo'>

========================= no tests ran in 0.11 seconds =========================

The test output parser will report the last one in file /home/.../test/testb/test/testc/test_last.py which is clearly wrong.

Reason is that the packagePrefix is not reset

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sleighsoftcommented, Apr 9, 2019

Any time frame on when this will be released? It currently makes the pytest integration unusable for me.

0reactions
ericsnowcurrentlycommented, Sep 3, 2019

This should be resolved in the most recent versions of the Python extension. If that is not the case then please create a new issue. (This one has a bit of outdated info, so better to start fresh.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changing standard (Python) test discovery - Pytest
Default behavior of pytest is to ignore duplicate paths specified from the command line. Example: ; To collect duplicate tests, use the --keep-duplicates...
Read more >
How should I structure a pytest test only package?
I created a python package which just contains test related stuff like pytest tests, pytest fixtures, test helper functions in util modules, ...
Read more >
pytest Documentation - Read the Docs
pytest discovers all tests following its Conventions for Python test discovery, so it finds both test_ prefixed functions.
Read more >
Getting Started With Testing in Python
In this in-depth tutorial, you'll see how to create Python unit tests, ... you want to place test.py above the package folder, so...
Read more >
UnitTest Framework - Py.test Module - Tutorialspoint
UnitTest Framework - Py.test Module, It was in 2004 that Holger Krekel renamed his std package, whose name was often confused with that...
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