wanderu / pytest-bandit

pytest plugin to execute bandit across a codebase
MIT License
14 stars 6 forks source link

INTERNALERROR on Windows #13

Open eugene-davis opened 5 years ago

eugene-davis commented 5 years ago

When running pytest-bandit on Windows (Python 3.5, 3.6, 3.7) I get the following message.

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\VssAdministrator\AppData\Roaming\Python\Python35\site-packages\_pytest\main.py", line 206, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "C:\Users\VssAdministrator\AppData\Roaming\Python\Python35\site-packages\_pytest\main.py", line 250, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "C:\Users\VssAdministrator\AppData\Roaming\Python\Python35\site-packages\pluggy\hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "C:\Users\VssAdministrator\AppData\Roaming\Python\Python35\site-packages\pluggy\manager.py", line 87, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "C:\Users\VssAdministrator\AppData\Roaming\Python\Python35\site-packages\pluggy\manager.py", line 81, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "C:\Users\VssAdministrator\AppData\Roaming\Python\Python35\site-packages\pluggy\callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "C:\Users\VssAdministrator\AppData\Roaming\Python\Python35\site-packages\pytest_bandit\plugin.py", line 172, in pytest_runtestloop
INTERNALERROR>     bandit_failures = BanditItem(compat_session).runtest()
INTERNALERROR>   File "C:\Users\VssAdministrator\AppData\Roaming\Python\Python35\site-packages\pytest_bandit\controller.py", line 53, in runtest
INTERNALERROR>     sys.stdout.write(os.linesep)
INTERNALERROR> ValueError: underlying buffer has been detached

==================== 3 passed, 15 skipped in 1.46 seconds =====================
Exception ignored in: <_io.TextIOWrapper mode='w' encoding='cp1252'>
ValueError: underlying buffer has been detached
##[error]Cmd.exe exited with code '3'.
##[section]Finishing: Tests
mattwwarren commented 5 years ago

This is an interesting issue you've uncovered. It is almost certainly because we override sys.stdout in order to get proper bandit output on the terminal.

But from a cursory Google search, this error would only happen if some other code has detached sys.stdout, which we don't do. So without a little context from the program you're testing, I'm not sure we can get to the bottom of this.

eugene-davis commented 5 years ago

I can provide the extra context for sure. First off, here's the PR where I tried to enable it on a particular project: https://github.com/tomtom-international/ebr-board/pull/9

This executes on Azure DevOps pipelines in the vs2017-win2016 image (defined here: https://github.com/tomtom-international/azure-pipeline-templates/blob/master/jobs/python.setup.py.yml#L31)

The actual PyTest command is executed here: https://github.com/tomtom-international/azure-pipeline-templates/blob/master/steps/python/python.build.yml#L29

Let me know how I can help.

mattwwarren commented 5 years ago

Hm, interesting, it's definitely specific to Windows. I'll try to get a development environment set up so I can debug a bit further. Thanks for the links, I should be able to use that Docker container.