Was previously using this extension for Python snippets: https://marketplace.visualstudio.com/items?itemName=cstrap.python-snippets
But found most of them useful/actually got in the way. As such I created my own, some of which were outright stolen from that page, others based on the ones on that page, others I’ve created myself:
- pdb
- env
- enc
- init
- property
- ifmain
- pytraises
- pytmdjango
- pytfixture
If one wants them, here’s the json definitions:
{
"pytestraises": {
"prefix": "pytraises",
"body": [
"with pytest.raises(Exception):",
" "
],
"description": "Insert a pytest.raises() block"
},
"Pytest Mark Django": {
"prefix": "pytmdjango",
"body": [
"pytestmark = pytest.mark.django_db"
],
"description": "Insert a pytestmark = pytest.mark.django_db"
},
"Pytest Fixture": {
"prefix": "pytfixture",
"body": [
"@pytest.fixture",
"def myfixture():",
" ",
" yield",
"",
""
],
"description": "Skeleton of a new pytest fixture"
},
"Insert PDB statement": {
"prefix": "pdb",
"body": [
"import pdb; pdb.set_trace()"
],
"description": "Inserts a pdb import & set trace"
},
"env": {
"prefix": "env",
"body": [
"#!/usr/bin/env python"
],
"description": "Inserts a python2 hashbang"
},
"env3": {
"prefix": "env3",
"body": [
"#!/usr/bin/env python3"
],
"description": "Inserts a python3 hashbang"
},
"enc": {
"prefix": "enc",
"body": [
"# -- coding=utf-8 --"
],
"description": "Insert a utf-8 file encoding line"
},
"init method": {
"prefix": "init",
"body": [
"def __init__(self, *args, **kwargs):",
" pass"
],
"description": "Insert an __init__ stub"
},
"Create Property": {
"prefix": "property",
"body": [
"@property",
"def myproperty(self):",
" return self._myproperty",
"",
"@myproperty.setter",
"def myproperty(self, value):",
" self._myproperty = value"
],
"description": "Creates a property with a getter & setter"
},
"Main method": {
"prefix": "ifmain",
"body": [
"def main():",
" pass",
"",
"if __name__ == \"__main__\":",
" main()"
],
"description": "Creates an if main block"
}
}