From cbcc18a71091eb8661aeca4fce9d0b7a51def986 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 20 Jun 2021 01:09:15 +0200 Subject: [PATCH] Improve support for VSCode --- .gitignore | 1 - .vscode/settings.json | 5 +++++ CHANGES.rst | 2 ++ doc/sandbox.rst | 11 +++++++++++ tests/test_commands.py | 11 ++++++++--- 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 0c9e9a14..5d4374d4 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ services/winscp.rnd .vs/VSWorkspaceState.json .vs/ProjectSettings.json f.01 -.vscode/settings.json funcs.py .pytest_cache .pytest_results diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..c619bb6b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "python.pythonPath": "${workspaceFolder}/.venv/bin/python", + "python.testing.pytestEnabled": true, + "python.testing.pytestPath": "${workspaceFolder}/.venv/bin/pytest" +} \ No newline at end of file diff --git a/CHANGES.rst b/CHANGES.rst index cce12e21..84bda4c7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,8 @@ mqttwarn changelog in progress =========== +- Improve support for VSCode + 2021-06-19 0.26.1 ================= diff --git a/doc/sandbox.rst b/doc/sandbox.rst index 17c86b02..4ed06629 100644 --- a/doc/sandbox.rst +++ b/doc/sandbox.rst @@ -42,6 +42,17 @@ will be able to launch the ``mqttwarn`` entrypoint without further ado. Otherwise, setup the virtualenv manually by invoking those commands:: + # On Linux python3 -m venv .venv source .venv/bin/activate + + # On Windows + python -m venv .venv + .venv/Scripts/activate + pip install --editable=.[test] --upgrade + +For properly configuring a virtualenv, please also read those fine resources: + +- https://code.visualstudio.com/docs/python/environments +- https://medium.com/@kylehayes/using-a-python-virtualenv-environment-with-vscode-b5f057f44c6a diff --git a/tests/test_commands.py b/tests/test_commands.py index e3201169..322ed6b1 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,12 +1,17 @@ import os import sys +from pathlib import Path import pytest +def get_mqttwarn_path(): + return Path(sys.executable).parent / Path("mqttwarn") + + def test_command_dump_config(capfd): - command = "mqttwarn make-config" + command = "{} make-config".format(get_mqttwarn_path()) os.system(command) stdout = capfd.readouterr().out @@ -16,7 +21,7 @@ def test_command_dump_config(capfd): def test_command_dump_samplefuncs(capfd): - command = "mqttwarn make-samplefuncs" + command = "{} make-samplefuncs".format(get_mqttwarn_path()) os.system(command) stdout = capfd.readouterr().out @@ -30,7 +35,7 @@ def test_command_standalone_plugin(capfd): if sys.platform.startswith("win"): raise pytest.xfail("Skipping test, fails on Windows") - command = """mqttwarn --plugin=log --options='{"message": "Hello world", "addrs": ["crit"]}'""" + command = """{} --plugin=log --options='{}'""".format(get_mqttwarn_path(), '{"message": "Hello world", "addrs": ["crit"]}') os.system(command) stderr = capfd.readouterr().err