For vi, place python.snippets
in ~/.config/coc/ultisnips/
For vscode, paste python.json
in CMD+p > Configure user snippets > Python
{ | |
"Test Suite": { | |
"prefix": "mts", | |
"body": [ | |
"# pyright: reportWildcardImportFromLibrary=false", | |
"from hamcrest import *", | |
"", | |
"", | |
"def test_$1():", | |
" $2" | |
] | |
}, | |
"Test Function": { | |
"prefix": "mtc", | |
"body": [ | |
"def test_$1($2):", | |
" $3" | |
] | |
}, | |
"Test Run Only": { | |
"prefix": "tro", | |
"body": [ | |
"import pytest", | |
"@pytest.mark.only" | |
] | |
}, | |
"Test Assert Stage": { | |
"prefix": "tas", | |
"body": [ | |
"import os", | |
"import pytest", | |
"STAGE = os.getenv(\"STAGE\")", | |
"if STAGE != \"dev\":", | |
" pytest.fail(msg=\"Test must be run in STAGE=dev\")" | |
] | |
}, | |
"Hamcrest Contains List": { | |
"prefix": "ccl", | |
"body": "assert_that($1, contains_inanyorder(*$2))" | |
}, | |
"Hamcrest Not None": { | |
"prefix": "cnn", | |
"body": "assert_that($1, is_(not_none()))" | |
}, | |
"Hamcrest Equality": { | |
"prefix": "ceq", | |
"body": "assert_that($1, is_(equal_to($2)))" | |
} | |
} |
{ | |
snippet mts "Test Suite" | |
# pyright: reportWildcardImportFromLibrary=false | |
from hamcrest import * | |
def test_$1(): | |
$2 | |
endsnippet | |
snippet mtc "Test Function" | |
def test_$1($2): | |
$3 | |
endsnippet | |
snippet tro "Test Run Only" | |
import pytest | |
@pytest.mark.only | |
endsnippet | |
snippet tas "Test Assert Stage" | |
import os | |
import pytest | |
STAGE = os.getenv("STAGE") | |
if STAGE != "dev":, | |
pytest.fail(msg="Test must be run in STAGE=dev") | |
endsnippet | |
snippet ccl "Hamcrest Contains List" | |
assert_that($1, contains_inanyorder(*$2)) | |
endsnippet | |
snippet cnn "Hamcrest Not None" | |
assert_that($1, is_(not_none())) | |
endsnippet | |
snipper ceq "Hamcrest Equality": { | |
assert_that($1, is_(equal_to($2))) | |
} | |
} | |