kaste / pytest Goto Github PK
View Code? Open in Web Editor NEWpytest runner and view annotator for sublime text
pytest runner and view annotator for sublime text
Good evening, dear @kaste.
First, congrats for this amazing package!
I am using Sublime Text 3211 on macOS Catalina and the annotations are not showing when saving the test. The status bar color is changing correctly, and the screen seems blink when I save the file (I think it's visible in the gif I posted). I tried with different files, directories and projects, and it didn't work. The package options seems to be ok and just the defaults are active, so "show_phantoms": true
. Any idea about what I can do?
Thank you in advance,
Gustavo
Hi!
I know it's a stupid question, but I cannot find the plugin settings file into my sublime text application support folder
~/Library/Application Support/Sublime Text 3/Packages
Am I supposed to create it myself? Is it stored somewhere else?
It would be maybe good idea to mention its position into the README
btw, my issue is that the standard python used for my builds in ST3 is brew python3 located
/usr/local/bin/python3
instead pytest is executed from python2.
How can I match them?
The test program (from the pytest.org example):
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
After running PyTest in Sublime Text 3 the output panel displays the following:
[WinError 2] The system cannot find the file specified
[cmd: ['python -m py.test', '--tb=auto', '-l', 'C:\\cygwin64\\home\\User1\\dir1\\test\\test_playground.py::test_answer', '--junit-xml=C:\\Users\\User1\\AppData\\Local\\Sublime Text 3\\Cache\\PyTest\\last-run.xml']]
[dir: C:\cygwin64\home\User1\dir1\test]
[path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\User1\AppData\Local\Microsoft\WindowsApps;c:\cygwin64\bin;C:\Python27]
Running the command from the command line produces:
c:\cygwin64\home\User1\dir1\test>python -m py.test --tb=auto -l C:\cygwin64\home\User1\dir1\test\test_playground.py --junit-xml=C:\Users\User1\AppData\Local\Sublime Text 3\Cache\PyTest\last-run.xml
============================= test session starts =============================
platform win32 -- Python 2.7.15, pytest-3.7.1, py-1.5.4, pluggy-0.7.1
rootdir: c:\cygwin64\home\User1\dir1\test, inifile:
--------- generated xml file: C:\Users\User1\AppData\Local\Sublime ----------
======================== no tests ran in 0.01 seconds =========================
ERROR: file not found: Text
Note the last two lines
Enclosing the --junit-xml parameter in double quotation marks produces the expected result:
c:\cygwin64\home\User1\dir1\test>python -m py.test --tb=auto -l C:\cygwin64\home\User1\dir1\test\test_playground.py --junit-xml="C:\Users\User1\AppData\Local\Sublime Text 3\Cache\PyTest\last-run.xml"
============================= test session starts =============================
platform win32 -- Python 2.7.15, pytest-3.7.1, py-1.5.4, pluggy-0.7.1
rootdir: c:\cygwin64\home\User1\dir1\test, inifile:
collected 1 item
test_playground.py F [100%]
================================== FAILURES ===================================
_________________________________ test_answer _________________________________
def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)
test_playground.py:6: AssertionError
generated xml file: C:\Users\User1\AppData\Local\Sublime Text 3\Cache\PyTest\last-run.xml
========================== 1 failed in 0.05 seconds ===========================
Is the problem I'm having caused by the package or could it be my setup?
Waiting for tests in background and looking just at status bar is kinda confusing.
Hi,
So this is happening all of a sudden, and its messing up all the icons throughout sublimetext
Run /opt/python/3.10/bin/python3 -m pytest -sv test
Errors parsing theme:
"class" is required in Packages/User/Adaptive.sublime-theme:66:2
Errors parsing theme:
"class" is required in Packages/User/Adaptive.sublime-theme:66:2
glGetError: GL_INVALID_OPERATION
Run /opt/python/3.10/bin/python3 -m pytest -sv test
Errors parsing theme:
"class" is required in Packages/User/Adaptive.sublime-theme:66:2
Errors parsing theme:
"class" is required in Packages/User/Adaptive.sublime-theme:66:2
Errors parsing theme:
"class" is required in Packages/User/Adaptive.sublime-theme:66:2
reloading settings Packages/User/Preferences.sublime-settings
reloading settings Packages/User/Preferences.sublime-settings
reloading settings Packages/User/Preferences.sublime-settings
reloading settings Packages/User/Preferences.sublime-settings
font face "Times" could not be found, defaulting to "Monospace"
File: Adaptive.sublime-theme
[
{
"class": "status_bar",
"layer0.tint":
[
8,
131,
8
],
"settings":
[
"pytest_is_green"
]
},
{
"class": "label_control",
"color":
[
19,
21,
32
],
"parents":
[
{
"class": "status_bar"
}
],
"settings":
[
"pytest_is_green"
]
},
{
"class": "status_bar",
"layer0.tint":
[
155,
7,
8
],
"settings":
[
"pytest_is_red"
]
},
{
"class": "label_control",
"color":
[
199,
191,
192
],
"parents":
[
{
"class": "status_bar"
}
],
"settings":
[
"pytest_is_red"
]
},
]
I believe a great enhancement for this package would be a command to create test stubs.
Such would parallel a function many IDEs, like Visual Studio, provide to make the life of the lazy programmer more comfortable.
app.py
def add(a: int, b: int) -> int:
return a + b
Will create this test file under the respective path with some test stub already in it:
/tests/test_app.py
import pytest
from ..app import add
def test_add(self):
"""Test for add."""
raise NotImplementedError("Test for add not implemented.")
Would like to see this package working for sublime text 4
T.i. write a minimal syntax file.
Basically, the same as the executable setting in SublimeLinter.
Use cases are to set it to ['python', '-m', 'pytest']
, although shlex.splitting would be more convenient probably python -m pytest
The tilde is not expanded in the "pytest" setting, so I should hardcode my home directory for the plugin to work ("~/.virtualenvs/${project_base_name}/Scripts/pytest.exe" does not work)
What about displaying the current test status in the status bar:
Like so
[12 | 3 ] - 12 passed, 3 failed
Or even with test coverage:
[12 | 3 | 74%] - 74% test coverage
The following warning
(virtual environment)/lib/python3.6/site-packages/_pytest/junitxml.py:436
(virtual environment)/lib/python3.6/site-packages/_pytest/junitxml.py:436: PytestDeprecationWarning: The 'junit_family' default value will change to 'xunit2' in pytest 6.0.
Add 'junit_family=legacy' to your pytest.ini file to silence this warning and make your suite compatible.
_issue_warning_captured(deprecated.JUNIT_XML_DEFAULT_FAMILY, config.hook, 2)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
- generated xml file: ~/.config/sublime-text-3/Cache/PyTest/last-run.xml -
Is caused by the following line:
Line 43 in 04cf2aa
The way to solve this, according to pytest:
junit_family
default value change to "xunit2"Deprecated since version 5.2.
The default value of
junit_family
option will change toxunit2
in pytest 6.0, given that this is the version supported by default in modern tools that manipulate this type of file.In order to smooth the transition, pytest will issue a warning in case the
--junitxml
option
is given in the command line butjunit_family
is not explicitly configured inpytest.ini
.PytestDeprecationWarning: The 'junit_family' default value will change to 'xunit2' in pytest 6.0. Add 'junit_family=legacy' to your pytest.ini file to silence this warning and make your suite compatible.
In order to silence this warning, users just need to configure the
junit_family
option explicitly:[pytest] junit_family=legacy
I believe this package would be more rounded if it provided an easy way to jump between implementation and test like this nice little package allows:
I installed the plugin yesterday, and found it was great! ๐ Thank you for sharing such a great plugin for sublime3, which make it much easier for me to develop in python with pytest and sublime.
But I can not figure out how to make the inline annotation feature working. I setup a project with only one test file and with the default setting of PyTest. The test run automatically on save, but do not annotate the views on failures.
Here is the screen short of my sublime.
There are some errors in the console, which I suppose to not relate to the problem:
modified
Run py.test --tb=auto -l /Users/zhangli/local_workshop/practice/pytest_subl/test_it.py
Traceback (most recent call last):
File "/Users/zhangli/Library/Application Support/Sublime Text 3/Packages/PyTest/pytest_exec.py", line 144, in parse_result
tree = etree.parse(get_report_file())
File "lxml.etree.pyx", line 3310, in lxml.etree.parse (src/lxml/lxml.etree.c:72517)
File "parser.pxi", line 1791, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:105979)
File "parser.pxi", line 1817, in lxml.etree._parseDocumentFromURL (src/lxml/lxml.etree.c:106278)
File "parser.pxi", line 1721, in lxml.etree._parseDocFromFile (src/lxml/lxml.etree.c:105277)
File "parser.pxi", line 1122, in lxml.etree._BaseParser._parseDocFromFile (src/lxml/lxml.etree.c:100227)
File "parser.pxi", line 580, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:94350)
File "parser.pxi", line 690, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:95786)
File "parser.pxi", line 618, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:94818)
OSError: Error reading file '/Users/zhangli/Library/Application Support/Sublime Text 3/Cache/PyTest/last-run.xml': failed to load external entity "/Users/zhangli/Library/Application Support/Sublime Text 3/Cache/PyTest/last-run.xml"
btw: I'm using the latest master branch of PyTest of commit c36cb0f
@kaste First of all a Big Thanks for putting up this very facile plugin!
Visual Studio annotates functions with symbols indicating whether they passed a test or whether test coverage for a function exists (https://res.infoq.com/news/2017/02/Live-Unit-Testing/en/resources/live-test.gif).
I believe such visual indication would be a huge power-up for PyTest as well because of its directly linking test result on the very function being tested.
That feature could be implemented via phantoms. Alternatively, in a less favored implementation, the gutter could be used to display the symbols.
Newer Sublime defaults to the auto
theme. But we cannot patch this as we first have to resolve between which themes Sublime actually switches.
Implement this as it is the first UX.
It would be great to have a shortcut to toggle inline annotations in views.
I am using ST4 on my MBP, and installed pytest yesterday.
I found there is a conflict or unwanted behaviour. That the "cmd+s" will run pytest runner is not acceptable, since by default "cmd+s" is to save changes in files.
I would like to see there is another keybinding to trigger pytest runner, other than "cmd+s".
The output pytest generates is just too long and verbose. A standard view is probably better bc you can move such views around.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.