astj / flake8-formatter-junit-xml

JUnit XML formatter for flake8
MIT License
17 stars 10 forks source link

Output file is appended to and not replaced #7

Closed e3krisztian closed 6 years ago

e3krisztian commented 6 years ago

Thanks for this nice project!

What I report below is a minor issue, that surprised me (worked around now).

Running flake8 --format=junit-xml --output-file=flake8.xml twice results in an invalid flake8.xml file (second run's output appended to previous runs output):

$ mkdir empty-dir
$ flake8 --format=junit-xml --output=flake8.xml empty-dir/
$ flake8 --format=junit-xml --output=flake8.xml empty-dir/
$ head flake8.xml 
<?xml version="1.0" ?>
<testsuites/>

<?xml version="1.0" ?>
<testsuites/>

It might be the behavior of flake8 --output-file and not this plugin, however with junit-xml it looked more natural to use the option --output-file than shell-redirect output to file.

astj commented 6 years ago

Thank you for reporting.

As you guess, current behavior is caused by flake8's base formatter. (ref: flake8!108). It can be confirmed by using default formatter (and target files with some violations).

Though this looks like flake8's intended behavior (ref: flake8#193, flake8#224), as you say this plugin should replace the whole file. I opened #8.

with default formatter ``` (venv) [github.com/astj/flake8-formatter-junit-xml]$ git diff diff --git a/tests/test_formatter.py b/tests/test_formatter.py index 91346ab..8a50f30 100644 --- a/tests/test_formatter.py +++ b/tests/test_formatter.py @@ -9,7 +9,6 @@ from junit_xml import TestSuite, TestCase filename = 'some/filename.py' error = style_guide.Violation('A000', filename, 2, 1, 'wrong wrong wrong', 'import os') - def create_formatter(**kwargs): kwargs.setdefault('output_file', None) kwargs.setdefault('tee', False) (venv) [github.com/astj/flake8-formatter-junit-xml]$ flake8 --output=flake8.txt tests/ (venv) [github.com/astj/flake8-formatter-junit-xml]$ flake8 --output=flake8.txt tests/ (venv) [github.com/astj/flake8-formatter-junit-xml]$ cat flake8.txt tests/test_formatter.py:12:1: E302 expected 2 blank lines, found 1 tests/test_formatter.py:12:1: E302 expected 2 blank lines, found 1 ```
astj commented 6 years ago

Just released a new version 0.0.5. It now replaces the file rather than appending.

e3krisztian commented 6 years ago

I can confirm the new version working.

Thank you!