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 run all tests, not singles

See original GitHub issue

Environment data

  • VS Code version: 1.34.0
  • Extension version (available under the Extensions sidebar): 2019.4.2
  • OS and version: Ubuntu 18.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Relevant/affected Python packages and their versions: –

Expected behaviour

Running a single test method should run it and not all method.

Actual behaviour

Running a test method run all the tests methods.

Alt Text

I have an idea of where the problem is: The item getted in my script seems not to be in the right order:

The dburlexpected param shuold be an URI and it is getted as the path of tests : 'tests/db_datapumping_urban_eco/test_db_preparator.py::test_tables_to_keep

If we run all the tests, it works perfectly fine.

moreover, if I run a single test with cli in a terminal , it works perfectly

Steps to reproduce:

  1. Install Python36, make a venv, call pytest with requests parameters.
  2. Config pytest in vcode to run with multiples arguments. (example: my config file)
  3. Run single tests or test file.

Config

settings.json (project)

{
    "python.pythonPath": "venv/bin/python3",
    "python.formatting.provider": "black",
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.linting.enabled": true,
    "python.testing.pyTestArgs": [
        "tests/db_datapumping_urban_eco/",
        "--dburl",
        "postgresql://postgres:postgres@localhost:5432/dev_in",
        "--dburl-src",
        "postgresql://postgres:postgres@localhost:5432/dev_src",
        "--dburl-out",
        "postgresql://postgres:postgres@localhost:5432/dev_out"
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pyTestEnabled": true
}

Logs

I refuse to pu logs for confidentiallity, but this part can be shown and is usefll

E           ValueError: The param 'dburl' must match with '^[\w+]+://(\w+)(?::(\w+))?@([^/:]+)(?::(\d+))?(?:/(\w*))?$', got 'tests/my_script/test_my_script_worker.py::test_generating_single_conn_if_same_dburl'

-------------- generated xml file: /tmp/tmp-18547QrRuTLLFZce9.xml --------------
===================== 10 passed, 6 error in 41.98 seconds ======================

Thanks for your help, testing is very important in development workflow!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
xNathancommented, Jun 26, 2019

Same here.

And I can reproduce with a simple snippet:

# file: tests/test_vscode_pytest.py

def test_case_one():
    print("debug msg here for case one")
    assert True


def test_case_two():
    print("debug msg here for case two")
    assert False


def test_case_three():
    print("debug msg here for case three")
    assert True

And add extra args to python.testing.pyTestArgs in .vscode/settings.json:

"python.testing.pyTestArgs": [
     "tests", "-sv"
]

If I click Run Test above test_case_three, pytest run all tests plus one more test_case_three.

Output:

============================= test session starts ==============================
platform linux -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0 -- /home/nathan/.local/share/virtualenvs/test_py-tXYlO0jG/bin/python
cachedir: .pytest_cache
rootdir: /tmp/test_py
collecting ... collected 4 items

tests/test_vscode_pytest.py::test_case_one debug msg here for case one
PASSED
tests/test_vscode_pytest.py::test_case_two debug msg here for case two
FAILED
tests/test_vscode_pytest.py::test_case_three debug msg here for case three
PASSED
tests/test_vscode_pytest.py::test_case_three debug msg here for case three
PASSED

=================================== FAILURES ===================================
________________________________ test_case_two _________________________________

    def test_case_two():
        print("debug msg here for case two")
>       assert False
E       assert False

tests/test_vscode_pytest.py:8: AssertionError
-------------- generated xml file: /tmp/tmp-183226zg5HAgpMjvN.xml --------------
====================== 1 failed, 3 passed in 0.06 seconds ======================

But it works fine with only one argument here.

So how does plugin pass args to pytest ?

0reactions
karrtikrcommented, Jul 17, 2019

validated

Read more comments on GitHub >

github_iconTop Results From Across the Web

With pytest, why are single test results different from running ...
The weird thing is, if I run all tests within a directory, all the tests pass. If I try to run a single...
Read more >
How to invoke pytest — pytest documentation
In general, pytest is invoked with the command pytest (see below for other ways to invoke pytest). This will execute all tests in...
Read more >
Pytest Tutorial: Executing Multiple Test Cases From Single File
With pytest you can run multiple test cases from a single file, or even run selective tests with custom markers or by grouping...
Read more >
Run set of tests - MATLAB runtests - MathWorks
This MATLAB function runs all the tests in your current folder and returns the results as a ... Run the test elements that...
Read more >
Effective Python Testing With Pytest
To run all tests except those that require database access, you can use pytest -m "not database_access" . You can even use an...
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