2

I am using Pylint, I am new to this tool, so to count the quality of my python project (test automation). I know that if I want to test the quality of one file I have to execute the following command (for Windows10):

pylint name_of_file.py

If I want to execute the whole directory, I need to create a python file named __init__.py in the above directory and then to execute this command:

pylint name_of_the_directory

Also, as I mentioned above, I also use PyCharm. Through the interface of this IDE, Pylint has a button named as Check Project which is validating the whole project. Please take a look on the screenshot of this interface:

enter image description here

An output from any of the above executions, would be like this:

something.py:12:4: C0111: Missing method docstring (missing-docstring)
something.py:16:4: C0111: Missing method docstring (missing-docstring)
something.py:20:4: C0111: Missing method docstring (missing-docstring)
something.py:25:4: C0111: Missing method docstring (missing-docstring)
something.py:31:4: C0111: Missing method docstring (missing-docstring)
something.py:35:4: C0111: Missing method docstring (missing-docstring)
something.py:39:4: C0111: Missing method docstring (missing-docstring)

What do I need: I want every after new build, the Pylint results to be saved in a specific directory under a .txt format file, having as a name the current timestamp followed by the current's project version (stored into a property file). To me (if I am not wrong), it's like keeping the log output fo Pylint execution. How can this happen?

In case is needed:

System information

  • Python version: 3.7
  • OS: Windows 10
  • IDE: PyCharm version: 2018.3.4
  • Framework: BDD Behave
dpapadopoulos
  • 1,834
  • 5
  • 23
  • 34
  • Do you care specifically about the Check Project button, or is some other way to run pylint and save the results ok? –  Feb 21 '19 at 12:36
  • "Check Project" is just another way to execute the validation of the whole project using pylint. I mentioned it because may someone know where do the results be saved after clicking on this button. I inserted as much information as I could so to help. – dpapadopoulos Feb 21 '19 at 12:38

1 Answers1

2

Working in the Windows command line, you can redirect output to the filename you need, and then display the contents of the file you just wrote.

pylint name_of_directory > <filename> 2>&1 | type <filename>

You can use slices of the %DATE% and %TIME% variables to get a unique filename with the timestamp.

>echo %DATE%
Thu 02/21/2019
>echo %DATE:~0,1%
T
>echo %DATE:~1,2%
hu
>echo %TIME%
 7:54:17.74

You'll have to figure out what parts you want and slice/append them into your desired name. Just trying to concatenate %DATE% and %TIME% will give you an invalid pathname. This question discussses formatting a filename with a timestamp.

Once you have the timestamp format you want, you can save your filename to a a variable to reference it just once:

set FILENAME="example.txt"; pylint <name_of_directory> > %FILENAME% 2>&1 | type %FILENAME%

Of course, this will just save it for the current command. See this question if you want to save it globally.

I assume there's a way to get PyCharm to run this command for you, but I cannot tell you how to do that.

  • `set FILENAME="example.txt"; pylint bdd > %FILENAME% 2>&1 | type %FILENAME%` –  Feb 21 '19 at 13:24
  • Then double-check your command. The `%NAME%` syntax is how Windows gets the value of a variable, so `%example.txt%` is meaningless and should never occur. –  Feb 21 '19 at 13:34
  • Bah, it looks like you have to set the variable and use it in two different commands. How annoying. –  Feb 21 '19 at 13:44
  • Yeap that's what I can see...there must be a solution for sure. All those guys who use pylint, they take the output by copy/paste? no way... :P – dpapadopoulos Feb 21 '19 at 13:46