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.

Test discovery fails with pytest-libfaketime

See original GitHub issue

Environment data

VS Code Version: 1.54.2 Commit: fd6f3bce6709b121a895d042d343d71f317d74e7 Date: 2021-03-11T00:56:09.783Z (4 days ago) Electron: 11.3.0 Chrome: 87.0.4280.141 Node.js: 12.18.3 V8: 8.7.220.31-electron.0 OS: Darwin x64 19.6.0

  • Extension version (available under the Extensions sidebar): v2021.2.636928669

  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.2

  • Type of virtual environment used: pipenv

  • Value of the python.languageServer setting: Jedi

Expected behaviour

Tests are correctly discoverd

Actual behaviour

Test discovery fails with when pytest-libfaketime is installed

Steps to reproduce:

I created a small repo to easily reproduce the issue: https://github.com/giallu/vscodetest

  1. clone the repo and create the virtual env with pipenv install
  2. Discover tests using pytest and root set to . or animals
  3. open the project in vscode: tests discovery and test running works
  4. install pytest-libfaketime with pipenv install pytest-libfaketime
  5. test discovery fails like this:
Test Discovery failed: 
SyntaxError: Unexpected end of JSON input

Logs

I am attaching here the Python Test Log window content; I tried in sequence: discover tests, run tests (install pytest-libfaketime), discover tests, run tests.

Interestingly, tests are a success before and after the library installation, it’s only the discovery phase that is failing.

python /Users/giallu/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /Users/giallu/vscodetest -s --cache-clear .
============================= test session starts ==============================
platform darwin -- Python 3.9.2, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
django: settings: vscodetest.settings (from ini)
rootdir: /Users/giallu/vscodetest, configfile: pytest.ini
plugins: django-4.1.0
collected 1 item

animal/tests.py .                                                        [100%]

- generated xml file: /var/folders/j8/_m5rss0s475_92j2207sdhxh0000gn/T/tmp-23058OVmOvk3C0G3U.xml -
============================== 1 passed in 0.52s ===============================
python /Users/giallu/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /Users/giallu/vscodetest -s --cache-clear .
Test Discovery failed: 
SyntaxError: Unexpected end of JSON input
python /Users/giallu/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /Users/giallu/vscodetest -s .
Test Discovery failed: 
SyntaxError: Unexpected end of JSON input
re-exec with libfaketime dependencies
============================= test session starts ==============================
platform darwin -- Python 3.9.2, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
django: settings: vscodetest.settings (from env)
rootdir: /Users/giallu/vscodetest, configfile: pytest.ini
plugins: libfaketime-0.1.2, django-4.1.0
collected 1 item

animal/tests.py .                                                        [100%]

- generated xml file: /var/folders/j8/_m5rss0s475_92j2207sdhxh0000gn/T/tmp-230583iuiT9nNMlnD.xml -
============================== 1 passed in 0.55s ===============================

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
kimadelinecommented, Mar 17, 2021

No there is nothing for you to do, don’t worry I haven’t forgotten about you 🙂

0reactions
giallucommented, Apr 12, 2021

Thank you. In the meanwhile I did exactly what you suggested and changed to https://github.com/adamchainz/time-machine that does not seem to suffer for the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode pytest test discovery fails - python - Stack Overflow
I spent ages trying to decipher this unhelpful error after creating a test that had import errors. Verify that your test suite can...
Read more >
Python Test Discovery Failed with no error message #11513
Issue Type: Bug I tried to run "Python: Discover Tests" but I got a message saying "Test discovery failed". I don't see any...
Read more >
MSTest test discovery fails when using a .testsettings file
When I select a .testsettings file, test discovery fails for all mstest tests. In the output windows "Tests" output, I see the message...
Read more >
Set up unit testing for Python code - Visual Studio
Setting up unit testing for Python code in Visual Studio takes full advantage of Test Explorer features to discover, run, and debug tests....
Read more >
Why is test discovery failing? : r/vscode - Reddit
... discover pytest -- --rootdir c:\Users\renan\Documents\Sources\Python-6502 -s --cache-clear Test Discovery failed: TypeError: Cannot read ...
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