PyCharm的个性化配置

PyCharm作为一款很好用的Python IDE,可以被定制化为使用更加舒适的工作环境,这里记录一下我自己的一些设置。

代码模板

Editor|File and Code Templates设置中,我配置了以下内容:

Python Script的模板从空白改为以下内容:

1
2
3
4
5
6
7
8
# -*- coding: utf-8 -*-
# ====================================== #
# @Author : **
# @Email : **
# @File : ${NAME}.py
# ALL RIGHTS ARE RESERVED UNLESS STATED.
# ====================================== #

添加一个新的Pytest模板,用于pytest测试框架:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pytest

# Import Some packages
import os

__author__ = "hanyanbo"
__copyright__ = "hanyanbo"
__license__ = "MIT"


def test_XXX():
"""XXX Tests"""
assert XXX(1) == 1
assert XXX(2) == 1
assert XXX(7) == 13
with pytest.raises(AssertionError):
XXX(-10)


def test_main(capsys):
"""CLI Tests"""
# capsys is a pytest fixture that allows asserts agains stdout/stderr
# https://docs.pytest.org/en/stable/capture.html
main(["7"])
captured = capsys.readouterr()
assert "The 7-th Fibonacci number is 13" in captured.out


def test_OTHERS():
pass