2 new commits in pytest:
https://bitbucket.org/hpk42/pytest/commits/b04ea4da194b/
Changeset: b04ea4da194b
User: hpk42
Date: 2013-11-21 14:54:46
Summary: simplify basedir isolation
Affected #: 1 file
diff -r 4c926afb69fc84051e08a2816085a58a74493ebf -r
b04ea4da194bbce91e32fc94fbfafa7ee20ee456 testing/conftest.py
--- a/testing/conftest.py
+++ b/testing/conftest.py
@@ -12,6 +12,7 @@
help=("run FD checks if lsof is available"))
def pytest_configure(config):
+ config._basedir = py.path.local()
if config.getvalue("lsof"):
try:
out = py.process.cmdexec("lsof -p %d" % pid)
@@ -42,12 +43,8 @@
config._numfiles = len(lines2)
raise AssertionError("\n".join(error))
[email protected] # XXX rather do item.addfinalizer
-def pytest_runtest_setup(item):
- item._oldir = py.path.local()
-
def pytest_runtest_teardown(item, __multicall__):
- item._oldir.chdir()
+ item.config._basedir.chdir()
if hasattr(item.config, '_numfiles'):
x = __multicall__.execute()
check_open_files(item.config)
https://bitbucket.org/hpk42/pytest/commits/4951204afadc/
Changeset: 4951204afadc
User: hpk42
Date: 2013-11-21 15:25:16
Summary: fix issue357 - special case "-k" expressions to allow for
filtering with simple strings that are not valid python expressions.
Examples: "-k 1.3" matches all tests parametrized with 1.3.
"-k None" filters all tests that have "None" in their name
and conversely "-k 'not None'".
Previously these examples would raise syntax errors.
Also add a note to the docs about what is allowed.
Affected #: 4 files
diff -r b04ea4da194bbce91e32fc94fbfafa7ee20ee456 -r
4951204afadcc1070e0d478c7ba4e8bdd29cd8fd CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -11,6 +11,13 @@
help with random "xdist" collection failures. Thanks to
Ronny Pfannschmidt and Donald Stufft for helping to isolate it.
+- fix issue357 - special case "-k" expressions to allow for
+ filtering with simple strings that are not valid python expressions.
+ Examples: "-k 1.3" matches all tests parametrized with 1.3.
+ "-k None" filters all tests that have "None" in their name
+ and conversely "-k 'not None'".
+ Previously these examples would raise syntax errors.
+
- fix issue384 by removing the trial support code
since the unittest compat enhancements allow
trial to handle it on its own
diff -r b04ea4da194bbce91e32fc94fbfafa7ee20ee456 -r
4951204afadcc1070e0d478c7ba4e8bdd29cd8fd _pytest/mark.py
--- a/_pytest/mark.py
+++ b/_pytest/mark.py
@@ -140,7 +140,13 @@
for name in colitem.function.__dict__:
mapped_names.add(name)
- return eval(keywordexpr, {}, KeywordMapping(mapped_names))
+ mapping = KeywordMapping(mapped_names)
+ if " " not in keywordexpr:
+ # special case to allow for simple "-k pass" and "-k 1.3"
+ return mapping[keywordexpr]
+ elif keywordexpr.startswith("not ") and " " not in keywordexpr[4:]:
+ return not mapping[keywordexpr[4:]]
+ return eval(keywordexpr, {}, mapping)
def pytest_configure(config):
diff -r b04ea4da194bbce91e32fc94fbfafa7ee20ee456 -r
4951204afadcc1070e0d478c7ba4e8bdd29cd8fd doc/en/example/markers.txt
--- a/doc/en/example/markers.txt
+++ b/doc/en/example/markers.txt
@@ -95,6 +95,17 @@
================= 1 tests deselected by '-khttp or quick'
==================
================== 2 passed, 1 deselected in 0.01 seconds
==================
+.. note::
+
+ If you are using expressions such as "X and Y" then both X and Y
+ need to be simple non-keyword names. For example, "pass" or "from"
+ will result in SyntaxErrors because "-k" evaluates the expression.
+
+ However, if the "-k" argument is a simple string, no such restrictions
+ apply. Also "-k 'not STRING'" has no restrictions. You can also
+ specify numbers like "-k 1.3" to match tests which are parametrized
+ with the float "1.3".
+
Registering markers
-------------------------------------
diff -r b04ea4da194bbce91e32fc94fbfafa7ee20ee456 -r
4951204afadcc1070e0d478c7ba4e8bdd29cd8fd testing/test_mark.py
--- a/testing/test_mark.py
+++ b/testing/test_mark.py
@@ -174,7 +174,9 @@
@pytest.mark.parametrize("spec", [
("interface", ("test_interface",)),
- ("not interface", ("test_nointer",)),
+ ("not interface", ("test_nointer", "test_pass")),
+ ("pass", ("test_pass",)),
+ ("not pass", ("test_interface", "test_nointer")),
])
def test_keyword_option_custom(spec, testdir):
testdir.makepyfile("""
@@ -182,6 +184,8 @@
pass
def test_nointer():
pass
+ def test_pass():
+ pass
""")
opt, passed_result = spec
rec = testdir.inline_run("-k", opt)
@@ -191,6 +195,24 @@
assert list(passed) == list(passed_result)
[email protected]("spec", [
+ ("None", ("test_func[None]",)),
+ ("1.3", ("test_func[1.3]",))
+])
+def test_keyword_option_parametrize(spec, testdir):
+ testdir.makepyfile("""
+ import pytest
+ @pytest.mark.parametrize("arg", [None, 1.3])
+ def test_func(arg):
+ pass
+ """)
+ opt, passed_result = spec
+ rec = testdir.inline_run("-k", opt)
+ passed, skipped, fail = rec.listoutcomes()
+ passed = [x.nodeid.split("::")[-1] for x in passed]
+ assert len(passed) == len(passed_result)
+ assert list(passed) == list(passed_result)
+
class TestFunctional:
def test_mark_per_function(self, testdir):
Repository URL: https://bitbucket.org/hpk42/pytest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit