I think that the person who writes the code of the product usually has the format & static check at the time of saving on the editor side during development.
On the other hand, testers and test engineers will challenge the automated test with GUI operation! I tend to get out of this when it becomes, so I tried to wake it up in the article after the introduction.
When writing automated test code, every time I save
--It automatically formats (= formats) the shape according to certain rules, such as the presence or absence of blank lines and spaces, and line breaks on lines that are too long. ――It points out redundant writing styles and points out unused modules / variables.
The state can be realized.
As a result, when multiple people are coding the automated test, the appearance of each automated test code is unified to some extent & unnecessary lines are reduced, making it easier to read and write.
This time, we will set it so that it (basically) adheres to the Python coding standard PEP8.
Execute the following command to install flake8 and autopep8.
> pip install flake8
> pip install autopep8
Add the following to the existing settings described in settings.json. Or, if the item already exists, overwrite it.
{
"editor.formatOnSave": true,
"python.linting.pylintEnabled": false,
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--ignore=E501"
],
"python.formatting.autopep8Args": [
"--max-line-length=200",
]
}
--ʻEditor.formatOnSave: Whether to format automatically when saving a file --
python.linting.pylintEnabled: Whether to use pylint --
python.linting.enabled: Whether to lint --
python.linting.flake8Args: Parameters to pass to flake8. This time
--ignore = E501 avoids E501's" line is too long "pointing out --
python.formatting.autopep8Args: Parameters to pass to autopep8. This time
--max-line-length = 200` sets the line feed limit to 200 characters
If you can do so far, after that, when you save the code with VS Code, it will automatically format and point out problems.
At the bottom of the screen, in the "Problem" tab, the pointed out content is displayed.
If it does not appear, please click on the x or △ mark at the bottom left.
If you can write automated test code with the same rules as the product development team, it is convenient because more people can maintain automated tests.
However, there are some situations where it is difficult to write automated test code according to the product coding standards.
For example, the limit on the number of characters in one line. At the time of development, if it is too long, it is required to insert an appropriate line break. In autopep8 used this time, line breaks are automatically set to fit in 79 characters by default.
However, when I'm writing an automated test in Selenium and I have to specify a long xpath, it's easier to see if it's stretched horizontally rather than a strange line break.
Therefore, this time, the limit on the number of characters in a line has been changed to 200. Please adjust here to your liking.
-[Introduce flake8 instead of pylint in VS Code Python development environment and set automatic formatting --Qiita](https://qiita.com/psychoroid/items/2c2acc06c900d2c0c8cb#%E3%83%95%E3%82% A1% E3% 82% A4% E3% 83% AB% E4% BF% 9D% E5% AD% 98% E6% 99% 82% E3% 81% ABlinting% E3% 82% 92% E3% 83% 81% E3% 82% A7% E3% 83% 83% E3% 82% AF% E3% 81% 99% E3% 82% 8B% E8% A8% AD% E5% AE% 9A% E3% 81% AB% E3% 81% 99% E3% 82% 8B) -Comfortably follow VS Code coding conventions --Qiita
Recommended Posts