Skip to content

Remove Console Report#175

Merged
camilamaia merged 2 commits intomasterfrom
remove-console
Jun 16, 2020
Merged

Remove Console Report#175
camilamaia merged 2 commits intomasterfrom
remove-console

Conversation

@camilamaia
Copy link
Copy Markdown
Member

  • Remove Console Report
  • Change -s option to argument
  • -h alias for help command

Closes #174
Closes #171

@camilamaia camilamaia self-assigned this Jun 12, 2020
@github-actions
Copy link
Copy Markdown

@camilamaia your pull request is missing a changelog!

@camilamaia camilamaia marked this pull request as ready for review June 12, 2020 13:34
@camilamaia
Copy link
Copy Markdown
Member Author

camilamaia commented Jun 12, 2020

@barbosa this is super weird, on my machine there tests that fail 🤷‍♀️

 pytest tests/unit/test_reporter.py
============================================== test session starts ==============================================
platform darwin -- Python 3.7.7, pytest-5.2.4, py-1.8.1, pluggy-0.13.1 -- /Users/camilamaia/envs/scanner/bin/python3.7
cachedir: .pytest_cache
rootdir: /Users/camilamaia/workspace/scanapi-org/scanapi, inifile: pytest.ini
plugins: mock-1.11.2, requests-mock-1.7.0, bdd-3.2.1, cov-2.8.1
collected 4 items

tests/unit/test_reporter.py::TestReporter::test_should_write_to_default_output[html] FAILED
tests/unit/test_reporter.py::TestReporter::test_should_write_to_default_output[markdown] FAILED
tests/unit/test_reporter.py::TestReporter::test_should_write_to_custom_output FAILED
tests/unit/test_reporter.py::TestReporter::test_should_handle_custom_templates PASSED

=================================================== FAILURES ====================================================
____________________________ TestReporter.test_should_write_to_default_output[html] _____________________________

self = <tests.unit.test_reporter.TestReporter object at 0x102d6ce50>, reporter_type = 'html'
mocker = <pytest_mock.plugin.MockFixture object at 0x102d6cd90>
mocked__render_content = <MagicMock name='_render_content' id='4342598800'>
mocked_open = <MagicMock name='open' spec='builtin_function_or_method' id='4342596496'>

    @pytest.mark.parametrize("reporter_type", ["html", "markdown"])
    def test_should_write_to_default_output(
        self, reporter_type, mocker, mocked__render_content, mocked_open
    ):
        mocked__render_content.return_value = "ScanAPI Report"
        reporter = Reporter(None, reporter_type)
>       reporter.write(fake_responses)

mocked__render_content = <MagicMock name='_render_content' id='4342598800'>
mocked_open = <MagicMock name='open' spec='builtin_function_or_method' id='4342596496'>
mocker     = <pytest_mock.plugin.MockFixture object at 0x102d6cd90>
reporter   = <scanapi.reporter.Reporter object at 0x102db9b90>
reporter_type = 'html'
self       = <tests.unit.test_reporter.TestReporter object at 0x102d6ce50>

tests/unit/test_reporter.py:27:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
scanapi/reporter.py:26: in write
    loader = PackageLoader("scanapi", "templates")
../../../envs/scanner/lib/python3.7/site-packages/jinja2/loaders.py:222: in __init__
    from pkg_resources import DefaultProvider, ResourceManager, \
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:960: in <module>
    class Environment:
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:964: in Environment
    self, search_path=None, platform=get_supported_platform(),
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:195: in get_supported_platform
    plat = 'macosx-%s-%s' % ('.'.join(_macosx_vers()[:2]), m.group(3))
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:370: in _macosx_vers
    version = platform.mac_ver()[0]
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/platform.py:615: in mac_ver
    info = _mac_ver_xml()
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/platform.py:592: in _mac_ver_xml
    pl = plistlib.load(f)
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/plistlib.py:939: in load
    if info['detect'](header):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

header = ''

    def _is_fmt_xml(header):
        prefixes = (b'<?xml', b'<plist')

        for pfx in prefixes:
>           if header.startswith(pfx):
E           TypeError: startswith first arg must be str or a tuple of str, not bytes

header     = ''
pfx        = b'<?xml'
prefixes   = (b'<?xml', b'<plist')

/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/plistlib.py:493: TypeError
__________________________ TestReporter.test_should_write_to_default_output[markdown] ___________________________

self = <tests.unit.test_reporter.TestReporter object at 0x10308b590>, reporter_type = 'markdown'
mocker = <pytest_mock.plugin.MockFixture object at 0x10308b7d0>
mocked__render_content = <MagicMock name='_render_content' id='4342599120'>
mocked_open = <MagicMock name='open' spec='builtin_function_or_method' id='4345525136'>

    @pytest.mark.parametrize("reporter_type", ["html", "markdown"])
    def test_should_write_to_default_output(
        self, reporter_type, mocker, mocked__render_content, mocked_open
    ):
        mocked__render_content.return_value = "ScanAPI Report"
        reporter = Reporter(None, reporter_type)
>       reporter.write(fake_responses)

mocked__render_content = <MagicMock name='_render_content' id='4342599120'>
mocked_open = <MagicMock name='open' spec='builtin_function_or_method' id='4345525136'>
mocker     = <pytest_mock.plugin.MockFixture object at 0x10308b7d0>
reporter   = <scanapi.reporter.Reporter object at 0x103030cd0>
reporter_type = 'markdown'
self       = <tests.unit.test_reporter.TestReporter object at 0x10308b590>

tests/unit/test_reporter.py:27:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
scanapi/reporter.py:26: in write
    loader = PackageLoader("scanapi", "templates")
../../../envs/scanner/lib/python3.7/site-packages/jinja2/loaders.py:222: in __init__
    from pkg_resources import DefaultProvider, ResourceManager, \
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:960: in <module>
    class Environment:
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:964: in Environment
    self, search_path=None, platform=get_supported_platform(),
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:195: in get_supported_platform
    plat = 'macosx-%s-%s' % ('.'.join(_macosx_vers()[:2]), m.group(3))
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:370: in _macosx_vers
    version = platform.mac_ver()[0]
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/platform.py:615: in mac_ver
    info = _mac_ver_xml()
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/platform.py:592: in _mac_ver_xml
    pl = plistlib.load(f)
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/plistlib.py:939: in load
    if info['detect'](header):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

header = ''

    def _is_fmt_xml(header):
        prefixes = (b'<?xml', b'<plist')

        for pfx in prefixes:
>           if header.startswith(pfx):
E           TypeError: startswith first arg must be str or a tuple of str, not bytes

header     = ''
pfx        = b'<?xml'
prefixes   = (b'<?xml', b'<plist')

/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/plistlib.py:493: TypeError
________________________________ TestReporter.test_should_write_to_custom_output ________________________________

self = <tests.unit.test_reporter.TestReporter object at 0x102a2ed10>
mocker = <pytest_mock.plugin.MockFixture object at 0x102a2e550>
mocked__render_content = <MagicMock name='_render_content' id='4345318864'>
mocked_open = <MagicMock name='open' spec='builtin_function_or_method' id='4342944400'>

    def test_should_write_to_custom_output(
        self, mocker, mocked__render_content, mocked_open
    ):
        mocked__render_content.return_value = "ScanAPI Report"
        reporter = Reporter("./custom/report-output.html", "html")
>       reporter.write(fake_responses)

mocked__render_content = <MagicMock name='_render_content' id='4345318864'>
mocked_open = <MagicMock name='open' spec='builtin_function_or_method' id='4342944400'>
mocker     = <pytest_mock.plugin.MockFixture object at 0x102a2e550>
reporter   = <scanapi.reporter.Reporter object at 0x103015110>
self       = <tests.unit.test_reporter.TestReporter object at 0x102a2ed10>

tests/unit/test_reporter.py:40:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
scanapi/reporter.py:26: in write
    loader = PackageLoader("scanapi", "templates")
../../../envs/scanner/lib/python3.7/site-packages/jinja2/loaders.py:222: in __init__
    from pkg_resources import DefaultProvider, ResourceManager, \
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:960: in <module>
    class Environment:
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:964: in Environment
    self, search_path=None, platform=get_supported_platform(),
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:195: in get_supported_platform
    plat = 'macosx-%s-%s' % ('.'.join(_macosx_vers()[:2]), m.group(3))
../../../envs/scanner/lib/python3.7/site-packages/pkg_resources/__init__.py:370: in _macosx_vers
    version = platform.mac_ver()[0]
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/platform.py:615: in mac_ver
    info = _mac_ver_xml()
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/platform.py:592: in _mac_ver_xml
    pl = plistlib.load(f)
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/plistlib.py:939: in load
    if info['detect'](header):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

header = ''

    def _is_fmt_xml(header):
        prefixes = (b'<?xml', b'<plist')

        for pfx in prefixes:
>           if header.startswith(pfx):
E           TypeError: startswith first arg must be str or a tuple of str, not bytes

header     = ''
pfx        = b'<?xml'
prefixes   = (b'<?xml', b'<plist')

/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/plistlib.py:493: TypeError
========================================== 3 failed, 1 passed in 1.86s ==========================================

Do you have any idea? I tried to debug and when I leave this part of the code, it works:

class TestConsoleReport:
     def test_should_print(self, mocker, mocked_print):
         console_reporter = Reporter(None, "console")
         console_reporter.write(fake_responses)

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 12, 2020

Codecov Report

Merging #175 into master will decrease coverage by 1.19%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #175      +/-   ##
==========================================
- Coverage   93.21%   92.02%   -1.20%     
==========================================
  Files          14       14              
  Lines         516      514       -2     
==========================================
- Hits          481      473       -8     
- Misses         35       41       +6     
Impacted Files Coverage Δ
scanapi/reporter.py 81.81% <ø> (-18.19%) ⬇️
scanapi/main.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e25323...cf12172. Read the comment docs.

@camilamaia camilamaia force-pushed the session branch 2 times, most recently from 226b91b to f7878a3 Compare June 12, 2020 21:32
Base automatically changed from session to master June 12, 2020 21:36
Comment thread README.md
```bash
$ scanapi --help
Usage: scanapi [OPTIONS]
Usage: scanapi [OPTIONS] [SPEC_PATH]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having SPEC_PATH before OPTIONS reinforces the idea that the former is required and the latter is optional, I think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. However, I looked for some documentation for this pattern and I didn't find it. Besides, I checked two terminal commands and the usage are in the same format we currently have:

  • gcc [OPTIONS] COMMAND
  • docker [OPTIONS] COMMAND
    So IMHO there's no problem here to keep using this format :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good examples. Although the idea of COMMAND (which is usually an imperative verb like: run, build, open, etc) is a bit different from SPEC_PATH (which sounds more like just another argument), I’m OK with both options.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I can see more clearly now. Thanks!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great discussion, I did not think about these points, thank you both! I agree that would be clearer to have [SPEC_PATH] before [OPTIONS], but I don't know how to do it actually 😂 This order ir generated by Click. I would need more investigation to figure out how to change it.

@barbosa
Copy link
Copy Markdown
Member

barbosa commented Jun 13, 2020

@camilamaia your pull request is missing a changelog!

☝️

In special for this PR, that we have a breaking change (from option to argument).

@barbosa
Copy link
Copy Markdown
Member

barbosa commented Jun 13, 2020

Weird that the tests are breaking in your machine. Have you tried removing all *.pyc files?

@camilamaia
Copy link
Copy Markdown
Member Author

@camilamaia your pull request is missing a changelog!

☝️

In special for this PR, that we have a breaking change (from option to argument).

Indeed! Done ✅

@camilamaia
Copy link
Copy Markdown
Member Author

Weird that the tests are breaking in your machine. Have you tried removing all *.pyc files?

@barbosa Yes, I did it and it keeps breaking 😞

@camilamaia
Copy link
Copy Markdown
Member Author

@barbosa I deleted the repo, recloned it and the error is still happening 😢
@gillianomenezes can you test if in your machine the tests pass?

@camilamaia
Copy link
Copy Markdown
Member Author

@loop0 figure out the problem with the failing tests!

The problem was with the mocked_open.

We were mocking the builtin method mocker.patch("builtins.open", mock) instead of the one in the reporter module mocker.patch("scanapi.reporter.open", mock). With this, the information was not loaded in the egg info.

When we were running the console test before, it was not mocking the open method, so this info was already available in memory. When we removed it, it crashed.

@camilamaia camilamaia merged commit fe52b79 into master Jun 16, 2020
@camilamaia camilamaia deleted the remove-console branch June 16, 2020 20:15
@camilamaia camilamaia mentioned this pull request Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove console report Change -s option to make it as an argument

4 participants