How to get consistent output from pylint? - pylint

I have a python project (~500 files) that I am trying to run pylint on. I find that when I run pylint multiple times on same code, it generates different results. I am specifically looking for cyclic dependencies. It reports a different number of errors each time. I run it using the following command:
pylint --persistent n myproject
With this I see that ~/.pylint.d doesn't get created. What is the reason for this variation ? How can I avoid it ? Can I make pylint generate same report when executed multiple times on unchanged code ?

Related

Teamcity build log prints one or several symbols per each line

Teamcity build log prints one or several symbols per each line.
I get the following output while build is running:
It is quite hard to read such output. Is there any way to force Teamcity print log for the entire length of the lines?
UPDATE: Our team found out that build log was affected by maven-surfire-plugin which was added to pom.xml. As we don't need this plugin for our current needs it was enough to remove it for resolving the problem.

Manually submitting coverage result to coveralls

So i have a script test.sh which firsts build a test docker image then runs the docker image which in turn runs the test. I'ld like to manually add a command to send the coverage result to coveralls.io
Can anyone help with a clue to the right direction i'm heading?
In general, manual submission to coveralls works as follows:
Add your repo in Coveralls, so that it's assigned a token.
Create a file .coveralls.yml which at minimum should contain this one line:
repo_token: "coveralls-token-for-your-repo"
Run tests in a way that generates some file with coverage information.
In Python, for example, you'd run python3 -m coverage ... and file .coverage will be created.
Submit to Coveralls, using a script that they provide.
Again, taking Python for example, you'd do:
$ pip3 install coveralls # a Python package for submitting to Coveralls
$ coveralls # yes, just this
The output might be:
Submitting coverage to coveralls.io...
Coverage submitted!
Job #10.1
https://coveralls.io/jobs/353453468453
The coveralls command will look for .coveralls.yml file in the current directory, so be sure to put it there.
If you're not using Python, however, for steps 3. and 4. you'll need to read about generating and submitting coverage data for your language in Coveralls docs. For selected languages the support is just as good as for Python, meaning that the commands might differ slightly, but it should still be a breeze.

Cannot generate coverage report using lcov

I'm trying to use lcov to generate coverage reports for my unit test suite, but I cannot even capture a tracefile. The error messages indicate that the source files cannot be found. The code is compiled by a Jenkins job on a build machine and the unit test are executed as a downstream job on a target machine. The source code and gcno files are transfered to the downstream job, which then executes the call to lcov. Here follows all the details, a cup of coffee might be needed.
On the build machine, make is executed in
/var/lib/jenkins/workspace/App-Coverage/BUILD/app/
The source code which I want coverage for is in subdirectories in
/var/lib/jenkins/workspace/App-Coverage/BUILD/app/packages/
The object files and gcno files are generated in an subdirectory o relative to the corresponding cpp file. So for example
/var/lib/jenkins/workspace/App-Coverage/BUILD/app/packages/subdir/Myclass.cpp
/var/lib/jenkins/workspace/App-Coverage/BUILD/app/packages/subdir/o/Myclass.o
/var/lib/jenkins/workspace/App-Coverage/BUILD/app/packages/subdir/o/Myclass.gcno
The source files and gcno files are copied to the unit test machine keeping the same folder structure and ends up in
/var/lib/jenkins/workspace/App-Coverage-Unittest/BUILD/app/
Note: There is a difference in the name of the workspace folder, "App-Coverage-Unittest" instead of "App-Coverage" since these two Jenkins jobs cannot have the same name.
So there is now for example
/var/lib/jenkins/workspace/App-Coverage-Unittest/BUILD/app/packages/subdir/Myclass.cpp
/var/lib/jenkins/workspace/App-Coverage-Unittest/BUILD/app/packages/subdir/o/Myclass.o
/var/lib/jenkins/workspace/App-Coverage-Unittest/BUILD/app/packages/subdir/o/Myclass.gcno
The unit tests are executed in
/opt/app/test/app
Using GCOV_PREFIX_STRIP and GCOV_PREFIX I make the gcda files appear in the same folders as the gcno files, so for example
/var/lib/jenkins/workspace/App-Coverage-Unittest/BUILD/app/packages/subdir/o/Myclass.gcno
/var/lib/jenkins/workspace/App-Coverage-Unittest/BUILD/app/packages/subdir/o/Myclass.gcda
Now I want to generate a coverage report using lcov, but I don't seem to understand how to set the paths correctly. The following examples where executed from /var/lib/jenkins/workspace/App-Coverage-Unittest/ by the Jenkins unittest job.
For example I tried
lcov -d BUILD/app/packages/ -c --no-external -o app.info -b /var/lib/jenkins/workspace/App-Coverage-Unittest/BUILD/app/
Reasoning: "-d BUILD/app/packages/" is what I want coverage for, "-b /var/lib/jenkins/workspace/App-Coverage-Unittest/BUILD/app/" is the root of my project in which I executed make (but on the build machine with a different workspace name...).
I also tried
lcov -d BUILD/app/packages/ --capture --no-external --output-file app.info
Reasoning : "-d BUILD/app/packages/" is what I want coverage for, don't set -b since relative path between each gcno/gcda and corresponding source file is the same as on the build machine, maybe lcov can figure it out.
In both cases get errors like "Cannot open source file /var/lib/jenkins/workspace/App-Coverage/BUILD/app/packages/subdir/Myclass.cpp"
Note: The workspace folder in this path is that of the build machine, not the unittest machine. I thought that this is what the -b option is intended to solve. Clearly this is very suspicious and a valuable clue.
I also get errors like "Cannot open source file ../../../packages/subdir/Myclass.h", which I guess has to do with how I include header files.
I have tried specifying all the paths here. Is it possible to generate the coverage report in the workspace of the unittest job using lcov, like I'm trying to do here? If yes, which are the correct paths to specify for lcov -d and -b flags? If not, what do I need to change to make it work?
Fortunately the answer is yes, it is possible. I got a reply from an lcov dev providing me with the solution, thank you Peter!
He pointed out that all source code paths are hard-coded during the compile step into the .gcno files. However, despite not finding the source files (and producing the warnings) lcov will generate code coverage output even when the source code cannot be found, based solely on the data found in .gcda and .gcno files. However, the genhtml step will fail because it won't be able to find the source code to annotate with code coverage data.
The solution is to use lcov's "geninfo_adjust_src_path" configuration setting. By using this setting, lcov is instructed to change source code paths as found in the .gcno files into the correct source code paths while writing the output .info files. So in my case:
lcov -d BUILD/app/packages/ --capture --no-external --output-file app.info
--rc geninfo_adjust_src_path="/var/lib/jenkins/workspace/App-Coverage/BUILD/
=> /var/lib/jenkins/workspace/App-Coverage-Unittest/BUILD/"
The warnings "Cannot open source file" will still be there when invoking lcov, but the resulting .info file will contain the correct paths and can therefore be converted to HTML on the test machine using genhtml.

TeamCity and CTest test results

I have a number of unit tests written for my project, executed with CTest. I would like to integrate the results into my TeamCity build. I've downloaded and set up the plugin for my testing framework (Boost Test).
The problem that I have run into is that the tests run with CTest output to Testing/Temporary/LastTest.log, whereas TeamCity is trying to read the results from standard out. To get around this, my testing step is.
make test
cat Testing/Temporary/LastTest.log
which works, but feels like a hack.
Is there any way to get TeamCity to read from this file in addition to standard out? Alternatively, is there any way to tell ctest to output to standard out in addition to this LastTest.log file?
This question is similar, but I would like it to work for all output rather than just on failure: CMake: setting an environmental variable for ctest (or otherwise getting failed test output from ctest/make test automatically)
Teamcity has additional build features which allow to process CTest reports. I am not sure if it'll work or not but you could try adding an additional build feature in your build step to read CTest report.

xcodebuild gives “profiling: invalid magic number”, doesn't generate coverage files

Let's get this out of the way first: This question is not a duplicate of this earlier question. I'll explain why below.
I'm running the command xcodebuild test -scheme 'ISO8601ForCocoa' SYMROOT=../build, and here's the output:
Executed 16 tests, with 0 failures (0 unexpected) in 0.047 (0.051) seconds
profiling: invalid magic number (0x656d6954)
profiling: invalid magic number (0x00000000)
** TEST SUCCEEDED **
The person who asked that earlier question got the same error message, but they fixed it by cleaning their build folder.
In my case, cleaning will not help, because I don't have a build folder yet. I still get this error message even on a completely fresh build. In fact, the .gcda and .gcno files are not even created, so there is nothing to clean.
xcodebuild puts build products in $SYMROOT, but stores profile products in $OBJROOT.
If you want to completely confine a build, including all intermediate and ultimate products, to a single directory, you need to set three build settings:
SYMROOT: Build Products Path (ultimate products, such as apps and test bundles)
OBJROOT: Intermediate Build Files Path (intermediate products, such as per-module object files—generated by the compiler, read by the linker—and .gcno/.gcda files)
SHARED_PRECOMPS_DIR: Precompiled Headers Cache Path (guess)

Resources