user1822881
user1822881

Reputation: 203

How to Run Py.test in PyScripter

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

Upvotes: 3

Views: 2055

Answers (4)

Macintosh_89
Macintosh_89

Reputation: 708

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)

Upvotes: 0

Macintosh_89
Macintosh_89

Reputation: 708

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

Upvotes: 3

hpk42
hpk42

Reputation: 23561

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

Upvotes: 0

NamPNQ
NamPNQ

Reputation: 379

You can use pytest in pydev :
http://pypi.python.org/pypi/pytest-pydev/0.1

Upvotes: 0

Related Questions