I'm using Python Tools for Visual Studio with py.test. I'm able to use pytest fine if I run the script without debugging, but when I run with debugging, the script crashes. Below is my code and the output that I get in the console window. I've searched for Google for answers but I've come up with nothing that solves this issue; it seems like no one has had this exact problem before. I'm running Visual Studio 2013, with PTVS 2.1 VS 2013.
#Code
import pytest
if __name__ == "__main__":
pytest.main("--resultlog=resultlog.txt")
#Output
! C:\Python34\lib\site-packages\colorama\ansitowin32.py
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\_pytest\main.py", line 80, in wrap_session
config.do_configure()
File "C:\Python34\lib\site-packages\_pytest\config.py", line 618, in do_configure
self.hook.pytest_configure(config=self)
File "C:\Python34\lib\site-packages\_pytest\core.py", line 521, in __call__
return self._docall(self.methods, kwargs)
File "C:\Python34\lib\site-packages\_pytest\core.py", line 528, in _docall
firstresult=self.firstresult).execute()
File "C:\Python34\lib\site-packages\_pytest\core.py", line 394, in execute
res = method(*args)
File "C:\Python34\lib\site-packages\_pytest\terminal.py", line 41, in pytest_configure
reporter = TerminalReporter(config, sys.stdout)
File "C:\Python34\lib\site-packages\_pytest\terminal.py", line 101, in __init__
self._tw = self.writer = py.io.TerminalWriter(file)
File "C:\Python34\lib\site-packages\py\_io\terminalwriter.py", line 130, in __init__
file = colorama.AnsiToWin32(file).stream
File "C:\Python34\lib\site-packages\colorama\ansitowin32.py", line 68, in __init__
convert = on_windows and not wrapped.closed and not on_emulated_windows and is_a_tty(wrapped)
AttributeError: '_DebuggerOutput' object has no attribute 'closed'
Q: How can this error be resolved so that I can debug from inside Visual Studio?
It's a bug in PTVS that has been fixed for the upcoming 2.2 release.
There's no build with the fix yet, but you can just apply it yourself, as it is in a .py file and does not require recompilation. The file that you need is:
C:\Users\...\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_debugger.py
Find class _DebuggerOutput in it, and add the following at the end of it:
def __getattr__(self, name):
return getattr(self.old_out, name)
Related
I am trying to use pyinstaller to create a .exe for someone else to run. The program uses mysql to ping a sql database and return information from it. When I run the program in PyCharm and with pyinstaller --onedir, everything works fine. However, when I bundle the program with --onefile, I get this error and traceback when running:
Traceback (most recent call last):
File "main.py", line 266, in <module>
File "main.py", line 88, in main
File "main.py", line 108, in grabData
File "sql.py", line 12, in SQLconnect
File "mysql\connector\pooling.py", line 286, in connect
File "mysql\connector\connection_cext.py", line 101, in __init__
File "mysql\connector\abstracts.py", line 1095, in connect
File "mysql\connector\connection_cext.py", line 199, in _open_connection
TypeError: argument 6 must be str, not None
For reference, here is the relevant line in the _open_connection function call in connection_cext.py:
self._cmysql = _mysql_connector.MySQL(
buffered=self._buffered,
raw=self._raw,
charset_name=charset_name,
connection_timeout=(self._connection_timeout or 0),
use_unicode=self._use_unicode,
auth_plugin=self._auth_plugin,
plugin_dir=self._plugin_dir,
)
The __init__ of this file has this code snippet:
self._plugin_dir = os.path.join(
os.path.dirname(os.path.abspath(_mysql_connector.__file__)),
"mysql",
"vendor",
"plugin",
)
I believe this plugin directory is the reason my code is failing, but I do not know how to bypass this or set it so that it references the right file at runtime. I know pyinstaller creates a temp file at runtime, but I don't know how to get the module to use it as the plugin directory.
Any help would be greatly appreciated! I really really wanna keep it in --onefile mode for simplicity for the user, so any solutions that maintain that would be ideal. Thanks!
I was forced into some software updates on my laptop (ThinkPad) and after the update when I tried to open Spyder (via Anaconda) and it won't open. I don't have any experience in errors like this or fixing this stuff (and I am aware this may be something that is super simple). Please help. This is the application launch error I am getting:
Traceback (most recent call last):
File "C:\Users\cyrra\anaconda3\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\app\start.py", line 205, in main
mainwindow.main()
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3651, in main
mainwindow = run_spyder(app, options, args)
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3526, in run_spyder
main.setup()
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 871, in setup
self.help = Help(self, css_path=css_path)
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\plugins\help\plugin.py", line 68, in __init__
color_scheme = self.get_color_scheme()
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\api\plugins.py", line 347, in get_color_scheme
return super(BasePluginWidget, self)._get_color_scheme()
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\plugins\base.py", line 446, in _get_color_scheme
return get_color_scheme(CONF.get('appearance', 'selected'))
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\gui.py", line 114, in get_color_scheme
color_scheme[key] = CONF.get("appearance", "%s/%s" % (name, key))
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\manager.py", line 228, in get
return config.get(section=section, option=option, default=default)
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\user.py", line 976, in get
return config.get(section=section, option=option, default=default)
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\user.py", line 513, in get
raise cp.NoOptionError(option, section)
configparser.NoOptionError: No option 'custom-1/background' in section: 'appearance'
Thanks,
Rachel
Did you try to run spyder on the terminal?
It should be prebuild in Anaconda.
Your Spyder config file should contain but is missing 'custom-1/background' in section: 'appearance'. If you have no experience, the easiest thing for you to do is uninstall and install Spyder (via Anaconda). Your other option is to find the config file called in line 513 of C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\user.py". Then open the config file (if it exists) and correct it. If the file is not found, search for that config file and place it in the expected location.
I'm trying to run flake8 on a docker django built like described here (tutorial page)
when building the docker image I get an error from flake8 which is run in an docker-compose file with like so
$ flake8 --ignore=E501,F401 .
multiprocessing.pool.RemoteTraceback:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **
File "/usr/local/lib/python3.8/multiprocessing/pool.py", line 48, in
return list(map(*
File "/usr/local/lib/python3.8/site-packages/flake8/checker.py", line 666, in
return checker.run_checks()
File "/usr/local/lib/python3.8/site-packages/flake8/checker.py", line 598, in run_checks
self.run_ast_checks()
File "/usr/local/lib/python3.8/site-packages/flake8/checker.py", line 495, in run_ast_checks
checker = self.run_check(plugin, tree=ast)
File "/usr/local/lib/python3.8/site-packages/flake8/checker.py", line 426, in run_check
self.processor.keyword_arguments_for( File "/usr/local/lib/python3.8/site-packages/flake8/processor.py", line 241, in keyword_arguments_for arguments[param] = getattr(self, param)
File "/usr/local/lib/python3.8/site-packages/flake8/processor.py", line 119, in file_tokens
self._file_tokens = list(
File "/usr/local/lib/python3.8/tokenize.py", line 525, in _tokenize
pseudomatch = _compile(PseudoToken).match(line, pos)
RuntimeError: internal error in regular expression engine
The above exception was the direct cause of the following exception: Traceback (most recent call last):
File "/usr/local/bin/flake8", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.8/site-packages/flake8/main/cli.py", line 18, in main
app.run(argv)
File "/usr/local/lib/python3.8/site-packages/flake8/main/application.py", line 393, in run
self._run(argv)
File "/usr/local/lib/python3.8/site-packages/flake8/main/application.py", line 381, in _run
self.run_checks()
File "/usr/local/lib/python3.8/site-packages/flake8/main/application.py", line 300, in run_checks
self.file_checker_manager.run()
File "/usr/local/lib/python3.8/site-packages/flake8/checker.py", line 329, in run
self.run_parallel()
File "/usr/local/lib/python3.8/site-packages/flake8/checker.py", line 293, in run_parallel
for ret in pool_map:
File "/usr/local/lib/python3.8/multiprocessing/pool.py", line 448, in <genexpr>
return (item for chunk in result for item in chunk)
File "/usr/local/lib/python3.8/multiprocessing/pool.py", line 865, in next
raise value
RuntimeError: internal error in regular expression engine
When I run flake8 with the --verbose flag, I get an error like this:
Fatal Python error: deletion of interned string failed
Python runtime state: initialized
KeyError: 'FILENAME_RE'
from the tokenizer.py
Does anyone know how to solve this?
Additional Data:
running docker-compose v1.25.4 on an raspberry 3 with buster lite.
Installed and compiled Python 3.8.2 from source with the flag --enableloadable-sqlite
Thanks for helping!
If you don't care for flake8, then just delete that line. It will work. I had the same problem.
I know this isn't an answer. I would add a comment instead if I could.
I encountered a very similar error profile when I had refactored and left a lot of data which formerly had been in the top of the project down in what became the package folder. There were 33621 files including .venv, .nox, .pytest_cache, .coverage.
File "/usr/lib/python3.8/multiprocessing/pool.py", line 448, in <genexpr>
return (item for chunk in result for item in chunk)
File "/usr/lib/python3.8/multiprocessing/pool.py", line 868, in next
raise value
IndexError: string index out of range
If you see a similar signature (the parallel processing engine being overwhelmed in some way and throwing an exception), you may want to review your project directory structure and make sure that you did not put this kind of data in your sources directories.
I have a python method which uses code foo = locals() which leads to a circular reference. If I run the code from console, say using python.exe run.py the code works and runs till the end. If I however run the same code in Visual Studio, it breaks on ValueError: Circular reference detected. The Visual studio is using exactly the same python interpreter as I call in the console. How is this possible?
Edit:
Traceback (most recent call last):
File "F:\Projekty\Betfair\Repos\Betfair\run.py", line 16, in <module>
text_query='Horse Racing'
File "C:\Program Files\conda\lib\site-
packages\betfairlightweight\endpoints\betting.py", line 33, in
list_event_types
response = self.request(method, params, session)
File "C:\Program Files\conda\lib\site-
packages\betfairlightweight\endpoints\baseendpoint.py", line 27, in request
request = self.create_req(method, params)
File "C:\Program Files\conda\lib\site-
packages\betfairlightweight\endpoints\baseendpoint.py", line 52, in
create_req
return json.dumps(payload)
File "C:\Program Files\conda\lib\json\__init__.py", line 230, in dumps
return _default_encoder.encode(obj)
File "C:\Program Files\conda\lib\json\encoder.py", line 198, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Program Files\conda\lib\json\encoder.py", line 256, in iterencode
return _iterencode(o, 0)
ValueError: Circular reference detected
There's no problem with running
foo = locals()
in a program, in either case. Circular references are very common, and shouldn't stop the program. However, it sounds like you're using a debugger which is trying to visualize the value foo, but can't support visualizing values with circular references. (It might be trying to convert the value to JSON.)
If your debugger can't handle circular references, look for an option to ignore foo in its inspector/watcher to avoid the crash.
I am a newbie to py.test , Please let me know how to run the py.test in PyScripter Editor.
I have tried in the belwo way but it doesn't work.
import pytest
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
pytest.main()
and on running the above script i get an error saying
Traceback (most recent call last):
File "<module1>", line 10, in <module>
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 474, in main
exitstatus = config.hook.pytest_cmdline_main(config=config)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 422, in __call__
return self._docall(methods, kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 433, in _docall
res = mc.execute()
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 351, in execute
res = method(**kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", line 107, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", line 92, in wrap_session
config.pluginmanager.notify_exception(excinfo, config.option)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 285, in notify_exception
res = self.hook.pytest_internalerror(excrepr=excrepr)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 422, in __call__
return self._docall(methods, kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 433, in _docall
res = mc.execute()
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 351, in execute
res = method(**kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", line 152, in pytest_internalerror
self.write_line("INTERNALERROR> " + line)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", line 140, in write_line
self._tw.line(line, **markup)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 181, in line
self.write(s, **kw)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 225, in write
self._file.write(msg)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 241, in write
self._writemethod(data)
TypeError: 'AsyncStream' object is not callable
Pleae do help me
The script appears to be wrong , as far as i know pytest.main can be used if you want your pytest should be run by python interpreter. You need have have your test under a directory.
For example your pytest file is called test_sample which has following content
===================================pytests/test_sample===============================
import pytest
def func(x): return x + 1
def test_answer(): assert func(3) == 5
==================================================================================
Then you can have the following code in python file which runs your test_sample
pytest.main(args=['-s', os.path.abspath('pytests')])
This should solve your problem
If you dont want python to run your pytests you can configure pyscripter runner to be run by pytests via tools-->configure tools and then add the pytests command line argument. you can then run you pytest from tools. By default pyscripter uses python interpreter as runner
You can use pytest in pydev :
http://pypi.python.org/pypi/pytest-pydev/0.1
Seems like PyScripter sets some sys.stdout stream that pytest does not recognize. I just tried to refine the handling from pytest's side. You can try using it with:
pip install -i http://pypi.testrun.org -U pytest
which should in particular install also the "py" lib which contains the TerminalWriting code. If that doesn't work, please file an file with the exact environment/PyScripter version you are using. And also the value of "import py ; print py.version".
HTH,
holger
import pytest,os
os.chdir("C:\Users\Public\Documents\Development\Python\<test_pytest.py>") #your file location
pytest.main(['-s', 'test_pytest.py'])
save the file . On Pyscripter go to Run-->Python Engine--> Internal
Run the test , it should work.
Somtime pyscripter doesn't pick up the change, you may have to reinitialise the python engine (Ctrl+F2)