-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nose -> pytest #4996
nose -> pytest #4996
Conversation
Yay, only 30 failures after initial run |
Really hoping this turns out well, ❤️ pytest |
1736f95
to
ff4751b
Compare
This is fanstastic work @smotornyuk. I'm still going through the main changes but one thing that caught my eye was that you are applying fixtures at the individual test level: class TestResourceViewCreate(object):
@pytest.mark.ckan_config("ckan.plugins", "image_view")
@pytest.mark.usefixtures("clean_db", "with_plugins")
def test_resource_view_create(self):
context = {}
params = self._default_resource_view_attributes()
result = helpers.call_action("resource_view_create", context, **params)
result.pop("id")
result.pop("package_id")
assert params == result
@pytest.mark.ckan_config("ckan.plugins", "image_view")
@pytest.mark.usefixtures("clean_db", "with_plugins")
def test_requires_resource_id(self):
context = {}
params = self._default_resource_view_attributes()
params.pop("resource_id")
with pytest.raises(logic.ValidationError):
helpers.call_action("resource_view_create", context, **params) This is fine of course but given our reliance on test classes I think that being able to apply fixtures at the class level makes the tests more readable and avoids duplication: @pytest.mark.ckan_config("ckan.plugins", "image_view")
@pytest.mark.usefixtures("clean_db", "with_plugins")
class TestResourceViewCreate(object):
def test_resource_view_create(self):
context = {}
params = self._default_resource_view_attributes()
result = helpers.call_action("resource_view_create", context, **params)
result.pop("id")
result.pop("package_id")
assert params == result
def test_requires_resource_id(self):
context = {}
params = self._default_resource_view_attributes()
params.pop("resource_id")
with pytest.raises(logic.ValidationError):
helpers.call_action("resource_view_create", context, **params) To make this work I had to slightly change the diff --git a/ckan/tests/pytest_ckan/fixtures.py b/ckan/tests/pytest_ckan/fixtures.py
index cc8521f56..216231ff9 100644
--- a/ckan/tests/pytest_ckan/fixtures.py
+++ b/ckan/tests/pytest_ckan/fixtures.py
@@ -56,7 +56,7 @@ def ckan_config(request, monkeypatch):
"""
_original = config.copy()
- for mark in request.node.own_markers:
+ for mark in request.node.iter_markers():
if mark.name == u"ckan_config":
monkeypatch.setitem(config, *mark.args)
yield config
Of course we can combine both approaches depending on the context but perhaps we should favour marking tests at the class level. WDYT? Of course I am assuming that changing all the references again would be a big task so maybe we can do it later |
The more we'll do now, the less we need to rework in future 😄 I'll try to move fixtures to class level wherever it possible - it not so hard with regexps and macros |
@smotornyuk I had a good look at this and as far as I'm concerned this is good to go. Let me know when you are done with the class level changes. BTW are these changes intended? |
On thing I've noticed though is that the tests are now noticeably slower (~6-7 mins with nose, ~10 min with pytest). We can investigate and improve it later, it might be related with the collection phase or the way we use fixtures. |
I'm actively using search-replace-with-regexp(sed, awk, etc.) here, and it, unfortunately, breaks code style in a number of places. In order to solve this problem, I'm formatting tests with
As for slow tests, unfortunately, it's not the collection phase but tests itself. Locally I'm using |
Both things make sense. I totally agree that is better to have tests without state leaking that the speed gains. We can refactor them later. Let me know when you are done with this PR and I'll merge |
Done. I've merged fixes from your |
nose tests are no more, long live pytest |
Long-time ago there was discussion related to test-runners(#3310).
nose
is not supported and thus we have a reason for switching into something new. In addition, current test complexity and constant problems with config/app initialization during tests just freaking me out. Long story short, I've decided to configurepytests
.