Skip to content

Pytest test discovery confused by packages #3936

@Flamefire

Description

@Flamefire

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-testingbugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions