From 66e6d16fdf6c5d1fc3acf6e76e6619e9e27aff07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Fri, 2 Apr 2021 11:15:34 +0200
Subject: [PATCH 05/18] misc: pylint fix unused-variable (#52630)

---
 tests/api/test_carddef.py          |   1 -
 tests/api/test_formdata.py         |   4 +-
 tests/backoffice_pages/test_all.py |  34 ++++----
 tests/form_pages/test_all.py       | 128 ++++++++++++++---------------
 tests/test_convert_to_sql.py       |   2 +-
 tests/test_formdata.py             |  27 +++---
 tests/test_formdef.py              |   3 +-
 tests/test_formdef_import.py       |   3 -
 tests/test_hobo.py                 |   1 -
 tests/test_misc.py                 |   7 +-
 tests/test_publisher.py            |   4 -
 tests/test_rootdirectory.py        |   4 +-
 tests/test_saml_auth.py            |  15 ++--
 tests/test_sql.py                  |  53 +++++-------
 tests/test_storage.py              |   8 +-
 tests/test_users.py                |   2 -
 tests/test_widgets.py              |   5 --
 tests/test_workflow_import.py      |  22 ++---
 tests/test_workflows.py            |  24 +++---
 tests/utilities.py                 |   4 +-
 20 files changed, 155 insertions(+), 196 deletions(-)

diff --git a/tests/api/test_carddef.py b/tests/api/test_carddef.py
index 1732ae6b..c2949444 100644
--- a/tests/api/test_carddef.py
+++ b/tests/api/test_carddef.py
@@ -209,7 +209,6 @@ def test_cards_import_csv(pub, local_user):
     assert resp.json['err'] == 0
     assert 'job' in resp.json['data']
     job_id = resp.json['data']['job']['id']
-    job = AfterJob.get(job_id)
     assert AfterJob.get(job_id).status == 'completed'
     # get job status from its api url
     resp = get_app(pub).get(sign_uri(resp.json['data']['job']['url'], user=local_user))
diff --git a/tests/api/test_formdata.py b/tests/api/test_formdata.py
index 51b70255..8815164c 100644
--- a/tests/api/test_formdata.py
+++ b/tests/api/test_formdata.py
@@ -1050,7 +1050,7 @@ def test_api_global_listing_ignored_roles(pub, local_user):
     data_class = formdef.data_class()
     data_class.wipe()
 
-    for i in range(10):
+    for _ in range(10):
         formdata = data_class()
         formdata.data = {'0': 'FOO BAR'}
         formdata.user_id = local_user.id
@@ -1099,7 +1099,7 @@ def test_api_include_anonymised(pub, local_user):
     data_class = formdef.data_class()
     data_class.wipe()
 
-    for i in range(10):
+    for _ in range(10):
         formdata = data_class()
         formdata.data = {'0': 'FOO BAR'}
         formdata.user_id = local_user.id
diff --git a/tests/backoffice_pages/test_all.py b/tests/backoffice_pages/test_all.py
index 63772251..249d6b30 100644
--- a/tests/backoffice_pages/test_all.py
+++ b/tests/backoffice_pages/test_all.py
@@ -816,8 +816,6 @@ def test_backoffice_card_field_columns(pub):
     resp_csv = resp.click('Export as CSV File')
     assert resp_csv.text.splitlines()[1].endswith(',plop,2020-04-24,Yes,aa')
 
-    resp_ods = resp.click('Export a Spreadsheet')
-
     resp_map = resp.click('Plot on a Map')
     geojson_url = re.findall(r'data-geojson-url="(.*?)"', resp_map.text)[0]
     resp_geojson = app.get(geojson_url)
@@ -1745,7 +1743,7 @@ def test_backoffice_multi_actions_using_session_user(pub):
     resp = resp.follow()
     assert 'Executing task &quot;Show user&quot; on forms' in resp.text
     assert '>completed<' in resp.text
-    for i, id in enumerate(sorted(ids, key=lambda x: int(x))):
+    for id in sorted(ids, key=lambda x: int(x)):
         content = formdef.data_class().get(id).evolution[-1].parts[0].content
         assert 'session_user=admin' in content
 
@@ -1856,7 +1854,7 @@ def test_backoffice_statistics_status_select(pub):
 
 
 def test_backoffice_map(pub):
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
     form_class = FormDef.get_by_urlname('form-title').data_class()
     number31 = [x for x in form_class.select() if x.data['1'] == 'FOO BAR 30'][0]
@@ -1893,7 +1891,7 @@ def test_backoffice_map(pub):
 
 
 def test_backoffice_geojson(pub):
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
     formdef = FormDef.get_by_urlname('form-title')
     formdef.fields.append(fields.MapField(id='4', label='4th field', type='map'))
@@ -2002,7 +2000,7 @@ def test_backoffice_global_remove_action(pub):
     workflow = Workflow.get_default_workflow()
     workflow.id = '2'
     action = workflow.add_global_action('FOOBAR')
-    remove = action.append_item('remove')
+    action.append_item('remove')
     trigger = action.triggers[0]
     trigger.roles = [x.id for x in pub.role_class.select() if x.name == 'foobar']
 
@@ -2123,7 +2121,7 @@ def test_backoffice_sidebar_user_template(pub):
 
 
 def test_backoffice_geolocation_info(pub):
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
     formdef = FormDef.get_by_urlname('form-title')
     formdef.geolocations = {'base': 'Geolocafoobar'}
@@ -3163,7 +3161,7 @@ def test_category_in_global_listing(pub):
         pytest.skip('this requires SQL')
         return
 
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
 
     app = login(get_app(pub))
@@ -3203,7 +3201,7 @@ def test_datetime_in_global_listing(pub):
         pytest.skip('this requires SQL')
         return
 
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
 
     app = login(get_app(pub))
@@ -3579,7 +3577,7 @@ def test_count_backoffice_drafts(pub):
 
 
 def test_menu_json(pub):
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
     resp = login(get_app(pub)).get('/backoffice/menu.json')
     menu_json_str = resp.text
@@ -3700,7 +3698,7 @@ def test_per_user_view_tracking_code(pub, emails, sms_mocking):
 
 
 def test_backoffice_resume_folded(pub):
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
     form_class = FormDef.get_by_urlname('form-title').data_class()
     number31 = [x for x in form_class.select() if x.data['1'] == 'FOO BAR 30'][0]
@@ -4236,7 +4234,7 @@ def test_backoffice_criticality_in_formdef_listing(pub):
     if not pub.is_using_postgresql():
         pytest.skip('this requires SQL')
         return
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
 
     wf = Workflow.get_default_workflow()
@@ -4283,7 +4281,7 @@ def test_backoffice_criticality_in_global_listing(pub):
         pytest.skip('this requires SQL')
         return
 
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
 
     wf = Workflow.get_default_workflow()
@@ -4326,7 +4324,7 @@ def test_backoffice_criticality_in_global_listing(pub):
 
 
 def test_backoffice_criticality_formdata_view(pub):
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
 
     wf = Workflow.get_default_workflow()
@@ -4958,7 +4956,7 @@ def test_workflow_jump_previous(pub):
 
 
 def test_workflow_jump_previous_on_submit(pub):
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
 
     wf = Workflow(name='blah')
@@ -5091,7 +5089,7 @@ def test_workflow_jump_previous_auto(pub):
 
 
 def test_backoffice_fields(pub):
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
 
     wf = Workflow(name='bo fields')
@@ -5101,7 +5099,7 @@ def test_backoffice_fields(pub):
             id='bo1', label='1st backoffice field', type='string', varname='backoffice_blah', required=False
         ),
     ]
-    st1 = wf.add_status('Status1')
+    wf.add_status('Status1')
     wf.store()
 
     formdef = FormDef.get_by_urlname('form-title')
@@ -5584,7 +5582,7 @@ def test_workflow_inspect_page(pub):
 
 
 def test_workflow_comment_required(pub):
-    user = create_user(pub)
+    create_user(pub)
     create_environment(pub)
 
     wf = Workflow(name='blah')
diff --git a/tests/form_pages/test_all.py b/tests/form_pages/test_all.py
index 37195572..4e4a0a5e 100644
--- a/tests/form_pages/test_all.py
+++ b/tests/form_pages/test_all.py
@@ -168,7 +168,7 @@ def test_home_with_user_forms(pub):
     formdef.enable_tracking_codes = True
     formdef.category_id = '1'
     wf = Workflow(name='status')
-    st1 = wf.add_status('Status1', 'st1')
+    wf.add_status('Status1', 'st1')
     wf.store()
     formdef.workflow_id = wf.id
     formdef.store()
@@ -276,7 +276,7 @@ def test_home_disabled(pub):
     assert not '<a href="test/">test</a>' in home.text
 
     # check access is denied
-    resp = get_app(pub).get('/test/', status=403)
+    get_app(pub).get('/test/', status=403)
 
 
 def test_home_disabled_with_redirect(pub):
@@ -411,7 +411,7 @@ def test_form_access(pub):
 
 
 def test_form_access_auth_context(pub):
-    user = create_user(pub)
+    create_user(pub)
 
     pub.load_site_options()
     if not pub.site_options.has_section('options'):
@@ -1101,7 +1101,7 @@ def test_form_multi_page_many_conditions(pub):
     formdef.data_class().wipe()
 
     with mock.patch('wcs.qommon.publisher.Substitutions.invalidate_cache') as invalidate_cache:
-        resp = get_app(pub).get('/test/')
+        get_app(pub).get('/test/')
         call_count = invalidate_cache.call_count
 
     for i in range(30):
@@ -1117,7 +1117,7 @@ def test_form_multi_page_many_conditions(pub):
 
     # check the cache doesn't get invalidated for every page
     with mock.patch('wcs.qommon.publisher.Substitutions.invalidate_cache') as invalidate_cache:
-        resp = get_app(pub).get('/test/')
+        get_app(pub).get('/test/')
         assert invalidate_cache.call_count <= call_count
 
 
@@ -1446,7 +1446,7 @@ def test_form_titles(pub):
 
 
 def test_form_summary_empty_pages(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.fields = [
         fields.PageField(id='0', label='1st page', type='page'),
@@ -1574,7 +1574,7 @@ def test_multipage_form_display_locations(pub):
 def test_form_visit_existing(pub):
     user = create_user(pub)
     formdef = create_formdef()
-    page = login(get_app(pub), username='foo', password='foo').get('/test/')
+    login(get_app(pub), username='foo', password='foo').get('/test/')
     formdef.data_class().wipe()
 
     formdata = formdef.data_class()()
@@ -1720,7 +1720,7 @@ def test_form_tracking_code(pub, nocache):
     assert resp.location.startswith('http://example.net/login')
 
     # or logged users that didn't enter the code:
-    user = create_user(pub)
+    create_user(pub)
     login(get_app(pub), username='foo', password='foo').get(
         'http://example.net/test/%s/' % formdata_id, status=403
     )
@@ -2076,7 +2076,7 @@ def test_form_tracking_code_remove_empty_draft(pub, nocache):
 
 
 def test_form_discard_draft(pub, nocache):
-    user = create_user(pub)
+    create_user(pub)
 
     formdef = create_formdef()
     formdef.fields = [fields.StringField(id='0', label='string')]
@@ -2247,7 +2247,7 @@ def test_form_tracking_code_as_variable(pub, nocache):
 
 
 def test_form_draft_with_file(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.fields = [fields.FileField(id='0', label='file', type='file')]
     formdef.enable_tracking_codes = True
@@ -2284,7 +2284,7 @@ def test_form_draft_with_file(pub):
 
 
 def test_form_draft_with_file_direct_validation(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.fields = [fields.FileField(id='0', label='file', type='file')]
     formdef.enable_tracking_codes = True
@@ -2309,7 +2309,7 @@ def test_form_draft_with_file_direct_validation(pub):
 
 
 def test_form_draft_with_date(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.fields = [fields.DateField(id='0', label='date', type='date')]
     formdef.enable_tracking_codes = True
@@ -2343,23 +2343,23 @@ def test_form_draft_from_prefill(pub):
     formdef.data_class().wipe()
 
     # no draft
-    resp = get_app(pub).get('/test/')
+    get_app(pub).get('/test/')
     assert formdef.data_class().count() == 0
     formdef.data_class().wipe()
 
     # draft created if there's been some prefilled fields
     formdef.fields[0].prefill = {'type': 'string', 'value': '{{request.GET.test|default:""}}'}
     formdef.store()
-    resp = get_app(pub).get('/test/?test=hello')
+    get_app(pub).get('/test/?test=hello')
     assert formdef.data_class().count() == 1
     formdef.data_class().wipe()
 
     # unless the call was made from an application
-    resp = get_app(pub).get('/test/?test=hello', headers={'User-agent': 'python-requests/0'})
+    get_app(pub).get('/test/?test=hello', headers={'User-agent': 'python-requests/0'})
     assert formdef.data_class().count() == 0
 
     # or a bot
-    resp = get_app(pub).get('/test/?test=hello', headers={'User-agent': 'Googlebot'})
+    get_app(pub).get('/test/?test=hello', headers={'User-agent': 'Googlebot'})
     assert formdef.data_class().count() == 0
 
 
@@ -2422,7 +2422,7 @@ def form_password_field_submit(app, password):
 
 
 def test_form_password_field_submit(pub):
-    user = create_user(pub)
+    create_user(pub)
     form_password_field_submit(get_app(pub), 'foobar')
     form_password_field_submit(get_app(pub), force_str(u'•	83003706'))
     form_password_field_submit(login(get_app(pub), username='foo', password='foo'), 'foobar\u00eb')
@@ -2461,7 +2461,7 @@ def test_form_multi_page_formdef_count_condition(pub):
 
 
 def test_form_multi_page_post_edit(pub):
-    user = create_user(pub)
+    create_user(pub)
 
     formdef = create_formdef()
     formdef.fields = [
@@ -2591,7 +2591,7 @@ def test_form_multi_page_post_edit(pub):
 
 
 def test_form_edit_autocomplete_list(pub):
-    user = create_user(pub)
+    create_user(pub)
 
     NamedDataSource.wipe()
     data_source = NamedDataSource(name='foobar')
@@ -2668,7 +2668,7 @@ def test_form_edit_autocomplete_list(pub):
 
 
 def test_form_count_dispatching(pub):
-    user = create_user(pub)
+    create_user(pub)
 
     formdef = create_formdef()
     formdef.fields = []
@@ -2681,7 +2681,7 @@ def test_form_count_dispatching(pub):
     jump.status = 'st2'
     st1.items.append(jump)
     jump.parent = st1
-    st2 = workflow.add_status('Status2', 'st2')
+    workflow.add_status('Status2', 'st2')
     workflow.store()
 
     formdef.workflow_id = workflow.id
@@ -2844,7 +2844,7 @@ def test_form_items_data_source_field_submit(pub):
 
 
 def test_form_page_string_prefill(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [
@@ -2858,7 +2858,7 @@ def test_form_page_string_prefill(pub):
 
 
 def test_form_page_profile_prefill(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [fields.StringField(id='0', label='string', prefill={'type': 'user', 'value': 'email'})]
@@ -2912,7 +2912,7 @@ def test_form_page_profile_first_name_prefill(pub):
 
 
 def test_form_page_formula_prefill(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [
@@ -2926,7 +2926,7 @@ def test_form_page_formula_prefill(pub):
 
 
 def test_form_page_template_prefill(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [
@@ -2958,7 +2958,7 @@ def test_form_page_template_prefill(pub):
 
 
 def test_form_page_session_var_prefill(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [
@@ -3054,7 +3054,7 @@ def test_form_page_template_list_prefill(pub):
 
 
 def test_form_page_query_string_list_prefill(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [
@@ -3095,7 +3095,7 @@ def test_form_page_query_string_list_prefill(pub):
 
 
 def test_form_page_profile_prefill_list(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [
@@ -3134,7 +3134,7 @@ def test_form_page_profile_prefill_list(pub):
 
 
 def test_form_page_formula_prefill_items_field(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [
@@ -3282,7 +3282,7 @@ def test_prefill_query_parameter(pub):
 
 
 def test_form_captcha(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [fields.StringField(id='0', label='Some field')]
@@ -3323,7 +3323,7 @@ def test_form_captcha(pub):
 
 
 def test_form_captcha_and_no_validation_page(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [fields.StringField(id='0', label='Some field')]
@@ -3350,7 +3350,7 @@ def test_form_captcha_and_no_validation_page(pub):
 
 
 def test_form_file_field_with_fargo(pub, fargo_url):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     file_field = fields.FileField(id='0', label='file')
     assert file_field.allow_portfolio_picking is False
@@ -3398,7 +3398,7 @@ def test_form_file_field_with_fargo(pub, fargo_url):
 
 
 def test_form_file_field_without_fargo(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     file_field = fields.FileField(id='0', label='file')
     file_field.allow_portfolio_picking = True
@@ -3710,7 +3710,7 @@ def test_form_table_field_submit(pub, emails):
     assert formdef.data_class().select()[0].data == {'0': [['a', 'c', 'e'], ['b', 'd', '']]}
 
     # check table is present in received email (via form_details).
-    user = create_user(pub)
+    create_user(pub)
     resp = login(get_app(pub), username='foo', password='foo').get('/test/')
     resp.form['f0$c-0-0'] = 'àà'  # would trigger column length bug (#23072)
     resp.form['f0$c-1-0'] = 'bb'
@@ -3784,7 +3784,7 @@ def test_form_table_rows_field_submit(pub, emails):
     assert '37.00' in resp.text
 
     # check table is present in received email (via form_details).
-    user = create_user(pub)
+    create_user(pub)
     resp = login(get_app(pub), username='foo', password='foo').get('/test/')
     resp.form['f0$element0$col0'] = 'àà'
     resp.form['f0$element0$col1'] = '14'
@@ -3849,7 +3849,7 @@ def test_form_table_rows_field_and_prefill(pub, emails):
     formdef.store()
     formdef.data_class().wipe()
 
-    resp = get_app(pub).get('/test/')
+    get_app(pub).get('/test/')
 
 
 def test_form_table_rows_add_row(pub):
@@ -4074,7 +4074,7 @@ def test_form_autocomplete_variadic_url(pub):
 
 
 def test_form_page_formula_prefill_user_name(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [
@@ -4090,7 +4090,7 @@ def test_form_page_formula_prefill_user_name(pub):
 
 
 def test_form_page_formula_prefill_session_user(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     formdef.fields = [
@@ -4428,7 +4428,7 @@ def test_form_ranked_items_randomize_order(pub):
     ]
     formdef.store()
     orders = {}
-    for i in range(10):
+    for _ in range(10):
         resp = get_app(pub).get('/test/')
         orders['%s-%s-%s' % (resp.text.index('foo'), resp.text.index('bar'), resp.text.index('baz'))] = True
     assert len(orders.keys()) > 1
@@ -4672,8 +4672,8 @@ def test_form_workflow_trigger(pub):
     st1.items.append(jump2)
     jump2.parent = st1
 
-    st2 = workflow.add_status('Status2', 'st2')
-    st3 = workflow.add_status('Status3', 'st3')
+    workflow.add_status('Status2', 'st2')
+    workflow.add_status('Status3', 'st3')
     workflow.store()
 
     formdef.workflow_id = workflow.id
@@ -4686,8 +4686,8 @@ def test_form_workflow_trigger(pub):
     assert formdef.data_class().get(formdata.id).status == 'wf-st1'
 
     app = get_app(pub)
-    resp = login(app, username='foo', password='foo').get('/')
-    resp = app.post(formdata.get_url() + 'jump/trigger/XXX', status=403)
+    login(app, username='foo', password='foo').get('/')
+    app.post(formdata.get_url() + 'jump/trigger/XXX', status=403)
 
     pub.role_class.wipe()
     role = pub.role_class(name='xxx')
@@ -4695,28 +4695,28 @@ def test_form_workflow_trigger(pub):
 
     jump.by = [role.id]
     workflow.store()
-    resp = app.post(formdata.get_url() + 'jump/trigger/XXX', status=403)
+    app.post(formdata.get_url() + 'jump/trigger/XXX', status=403)
 
     user.roles = [role.id]
     user.store()
-    resp = app.post(formdata.get_url() + 'jump/trigger/XXX', status=302)
+    app.post(formdata.get_url() + 'jump/trigger/XXX', status=302)
 
     formdata = formdef.data_class().get(formdata.id)
     assert formdata.status == 'wf-st2'
 
     formdata.status = 'wf-st1'
     formdata.store()
-    resp = app.post(formdata.get_url() + 'jump/trigger/YYY', status=403)
+    app.post(formdata.get_url() + 'jump/trigger/YYY', status=403)
     jump2.by = [role.id]
     workflow.store()
-    resp = app.post(formdata.get_url() + 'jump/trigger/YYY', status=302)
+    app.post(formdata.get_url() + 'jump/trigger/YYY', status=302)
     formdata = formdef.data_class().get(formdata.id)
     assert formdata.status == 'wf-st3'
     assert formdata.workflow_data.get('_markers_stack') == [{'status_id': 'st1'}]
 
     formdata.status = 'wf-st1'
     formdata.store()
-    resp = app.post(
+    app.post(
         formdata.get_url() + 'jump/trigger/YYY',
         params=json.dumps({'data': {'foo': 'bar'}}),
         content_type='application/json',
@@ -4867,7 +4867,7 @@ def test_form_worklow_comments_on_same_status(pub):
 
 
 def test_display_message(pub):
-    user = create_user(pub)
+    create_user(pub)
 
     formdef = create_formdef()
     formdef.fields = []
@@ -4971,7 +4971,7 @@ def test_display_message(pub):
 
 
 def test_workflow_condition_on_message(pub):
-    user = create_user(pub)
+    create_user(pub)
 
     formdef = create_formdef()
     formdef.fields = []
@@ -5011,7 +5011,7 @@ def test_workflow_condition_on_message(pub):
 
 
 def test_session_cookie_flags(pub):
-    formdef = create_formdef()
+    create_formdef()
     app = get_app(pub)
     resp = app.get('/test/', status=200)
     assert resp.headers['Set-Cookie'].startswith('sessionid-')
@@ -5214,7 +5214,7 @@ def test_form_page_profile_verified_radio_item_prefill(pub):
 
 
 def test_item_field_from_cards(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
 
@@ -5526,7 +5526,7 @@ def test_item_field_from_cards_check_lazy_live(pub):
 
 
 def test_item_field_with_disabled_items(http_requests, pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     ds = {'type': 'json', 'value': 'http://remote.example.net/json'}
@@ -5634,7 +5634,7 @@ def test_item_field_with_disabled_items(http_requests, pub):
 
 
 def test_items_field_with_disabled_items(http_requests, pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
     ds = {'type': 'json', 'value': 'http://remote.example.net/json'}
@@ -5689,7 +5689,7 @@ def test_items_field_with_disabled_items(http_requests, pub):
 def test_item_field_autocomplete_json_source(http_requests, pub, error_email, emails):
     if pub.is_using_postgresql():
         pub.loggederror_class.wipe()
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
 
@@ -5997,7 +5997,7 @@ remote.example.net = 1234
 
 
 def test_item_field_autocomplete_jsonp_source(http_requests, pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
 
@@ -6047,7 +6047,7 @@ def test_item_field_autocomplete_jsonp_source(http_requests, pub):
 
 
 def test_item_field_autocomplete_cards_source(pub):
-    user = create_user(pub)
+    create_user(pub)
     formdef = create_formdef()
     formdef.data_class().wipe()
 
@@ -6376,7 +6376,7 @@ def test_form_status_appearance_keywords(pub):
 
 
 def test_user_global_action(pub):
-    user = create_user(pub)
+    create_user(pub)
 
     workflow = Workflow.get_default_workflow()
     workflow.id = '2'
@@ -6422,7 +6422,7 @@ def test_user_global_action(pub):
 
 
 def test_user_global_action_same_status_store(pub):
-    user = create_user(pub)
+    create_user(pub)
 
     workflow = Workflow.get_default_workflow()
     workflow.id = '2'
@@ -6479,7 +6479,7 @@ def test_user_global_action_same_status_store(pub):
 
 
 def test_condition_on_action(pub, emails):
-    user = create_user(pub)
+    create_user(pub)
 
     workflow = Workflow.get_default_workflow()
     # change email subjects to differentiate them
@@ -6540,7 +6540,7 @@ def test_condition_on_action(pub, emails):
 def test_user_global_action_along_form(pub):
     # check it's possible to click on a global action button even if there's a
     # form with required fields.
-    user = create_user(pub)
+    create_user(pub)
 
     workflow = Workflow.get_default_workflow()
     workflow.id = '2'
@@ -6592,7 +6592,7 @@ def test_user_global_action_along_form(pub):
 
 
 def test_email_actions(pub, emails):
-    user = create_user(pub)
+    create_user(pub)
 
     workflow = Workflow.get_default_workflow()
     workflow.id = '2'
@@ -7022,7 +7022,7 @@ def test_field_live_items_condition(pub):
     ]
     formdef.store()
 
-    user = create_user(pub)
+    create_user(pub)
     app = login(get_app(pub), username='foo', password='foo')
     resp = app.get('/foo/')
     assert 'f1$element0' in resp.form.fields
@@ -8230,7 +8230,7 @@ def test_frontoffice_workflow_form_with_impossible_condition(pub):
 
 
 def test_choice_button_ignore_form_errors(pub):
-    user = create_user(pub)
+    create_user(pub)
 
     formdef = create_formdef()
     formdef.roles = [logged_users_role().id]
diff --git a/tests/test_convert_to_sql.py b/tests/test_convert_to_sql.py
index cf9b0ea3..e28ed690 100644
--- a/tests/test_convert_to_sql.py
+++ b/tests/test_convert_to_sql.py
@@ -101,7 +101,7 @@ def test_database_does_not_exist(pub):
 
 
 def test_already_migrated_fails():
-    pub = create_temporary_pub(sql_mode=True)
+    create_temporary_pub(sql_mode=True)
     with pytest.raises(CommandError) as excinfo:
         call_command('convert_to_sql', '-d', 'example.net', '--database', 'foobar')
     assert str(excinfo.value) == 'tenant already using postgresql'
diff --git a/tests/test_formdata.py b/tests/test_formdata.py
index a1c6b3ca..d5ab5bca 100644
--- a/tests/test_formdata.py
+++ b/tests/test_formdata.py
@@ -513,7 +513,7 @@ def test_backoffice_field_varname(pub):
     wf.backoffice_fields_formdef.fields = [
         fields.StringField(id='bo1', label='1st backoffice field', type='string', varname='backoffice_blah'),
     ]
-    st1 = wf.add_status('Status1')
+    wf.add_status('Status1')
     wf.store()
 
     formdef.workflow_id = wf.id
@@ -940,11 +940,11 @@ def test_lazy_formdata_live_item(pub):
 def test_lazy_formdata_queryset(pub, variable_test_data):
     lazy_formdata = variable_test_data
     data_class = lazy_formdata._formdef.data_class()
-    for i in range(6):
+    for _ in range(6):
         formdata = data_class()
         formdata.just_created()
         formdata.store()
-    for i in range(4):
+    for _ in range(4):
         formdata = data_class()
         formdata.just_created()
         formdata.jump_status('finished')
@@ -1101,12 +1101,12 @@ def test_lazy_formdata_queryset_filter(pub, variable_test_data):
     formdef.workflow = wf
     formdef.store()
     data_class = lazy_formdata._formdef.data_class()
-    for i in range(6):
+    for _ in range(6):
         formdata = data_class()
         formdata.data = {'0': 'bar', '1': True, 'bo1': 'plop1', '10': '3'}
         formdata.just_created()
         formdata.store()
-    for i in range(4):
+    for _ in range(4):
         formdata = data_class()
         formdata.data = {
             '0': 'foo',
@@ -1523,17 +1523,14 @@ def test_lazy_variables_length(pub, variable_test_data):
     pub.substitutions.reset()
     pub.substitutions.feed(formdef)
     pub.substitutions.feed(formdata)
-    for mode in (None, 'lazy'):
-        pub.substitutions.reset()
-        pub.substitutions.feed(formdata)
-        assert WorkflowStatusItem.compute('{{ form_var_foo_foo|length }}') == '3'
-        assert WorkflowStatusItem.compute('{% if form_var_foo_foo|length_is:3 %}ok{% endif %}') == 'ok'
-        assert (
-            WorkflowStatusItem.compute(
-                '{% if form_var_foo_foo|length_is:form_var_foo_foo_baz_baz %}ok{% endif %}'
-            )
-            == 'ok'
+    assert WorkflowStatusItem.compute('{{ form_var_foo_foo|length }}') == '3'
+    assert WorkflowStatusItem.compute('{% if form_var_foo_foo|length_is:3 %}ok{% endif %}') == 'ok'
+    assert (
+        WorkflowStatusItem.compute(
+            '{% if form_var_foo_foo|length_is:form_var_foo_foo_baz_baz %}ok{% endif %}'
         )
+        == 'ok'
+    )
 
 
 def test_lazy_map_variable(pub, variable_test_data):
diff --git a/tests/test_formdef.py b/tests/test_formdef.py
index bc369b00..9b800064 100644
--- a/tests/test_formdef.py
+++ b/tests/test_formdef.py
@@ -341,7 +341,7 @@ def test_unused_file_removal_job(pub):
         clean_unused_files(pub)
         assert os.listdir(os.path.join(pub.app_dir, 'uploads')) == []
 
-        for i in range(5):
+        for _ in range(5):
             formdata = formdef.data_class()()
             formdata.just_created()
             formdata.data = {
@@ -574,7 +574,6 @@ def test_pickle_2to3_conversion(pub):
     formdef.store()
 
     formdef_id = formdef.id
-    workflow_id = workflow.id
     formdef_filename = os.path.join(formdef.get_objects_dir(), str(formdef.id))
     workflow_filename = os.path.join(workflow.get_objects_dir(), str(workflow.id))
 
diff --git a/tests/test_formdef_import.py b/tests/test_formdef_import.py
index 222afa9d..d766b302 100644
--- a/tests/test_formdef_import.py
+++ b/tests/test_formdef_import.py
@@ -288,7 +288,6 @@ def test_workflow_reference():
     assert f2.workflow_id == formdef.workflow_id
 
     formdef_xml_with_id = formdef.export_to_xml(include_id=True)
-    formdef_xml_without_id = formdef.export_to_xml(include_id=False)
 
     # check there's no reference to a non-existing workflow
     Workflow.wipe()
@@ -323,7 +322,6 @@ def test_category_reference():
     assert f2.category_id == formdef.category_id
 
     formdef_xml_with_id = formdef.export_to_xml(include_id=True)
-    formdef_xml_without_id = formdef.export_to_xml(include_id=False)
 
     # check there's no reference to a non-existing category
     Category.wipe()
@@ -551,7 +549,6 @@ def test_workflow_roles():
     assert fd2.workflow_roles.get('_receiver') == role.id
 
     xml_export = export_to_indented_xml(formdef, include_id=True)
-    xml_export_no_id = export_to_indented_xml(formdef, include_id=False)
 
     # same id, different name
     role.name = 'blah 2'
diff --git a/tests/test_hobo.py b/tests/test_hobo.py
index f162941e..7e2c1d3b 100644
--- a/tests/test_hobo.py
+++ b/tests/test_hobo.py
@@ -301,7 +301,6 @@ def test_update_profile():
 
     formdef = UserFieldsFormDef(pub)
     field_labels = [force_str(x.get('label')) for x in profile.get('fields') if not x.get('disabled')]
-    field_ids = [x.get('name') for x in profile.get('fields') if not x.get('disabled')]
     assert [x.label for x in formdef.fields] == field_labels
     for field_id in [pub.cfg['users']['field_email']] + pub.cfg['users']['field_name']:
         assert field_id in [x.id for x in formdef.fields]
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 358cd676..61978a3c 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -304,7 +304,7 @@ def test_date_format():
 
 
 def test_get_as_datetime():
-    pub = create_temporary_pub()
+    create_temporary_pub()
     datetime_value = datetime.datetime(2017, 4, 25, 12, 0)
     assert get_as_datetime('2017-04-25 12:00') == datetime_value
     assert get_as_datetime('2017-04-25 12:00:00') == datetime_value
@@ -474,7 +474,7 @@ def test_email_signature_rst_pipes(emails):
 
 
 def test_email_plain_with_attachments(emails):
-    pub = create_temporary_pub()
+    create_temporary_pub()
 
     jpg = PicklableUpload('test.jpeg', 'image/jpeg')
     jpg_content = open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()
@@ -601,7 +601,6 @@ M. Francis Kuntz
     assert emails.emails['test']['msg'].get_content_subtype() == 'alternative'
     assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
     assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
-    text = emails.emails['test']['msg'].get_payload()[0].get_payload(decode=True)
     html = emails.emails['test']['msg'].get_payload()[1].get_payload(decode=True)
     assert html.count(b'<ol') == 1
     assert not b'<ul' in html
@@ -611,7 +610,7 @@ M. Francis Kuntz
 
 @pytest.mark.skipif('docutils is None')
 def test_email_with_unexpected_transition(emails):
-    pub = create_temporary_pub()
+    create_temporary_pub()
     mail_body = '''
 Value:
  A
diff --git a/tests/test_publisher.py b/tests/test_publisher.py
index f5defd8a..35f899aa 100644
--- a/tests/test_publisher.py
+++ b/tests/test_publisher.py
@@ -72,10 +72,6 @@ def test_plaintext_error():
 
 def test_finish_failed_request():
     pub.USE_LONG_TRACES = False
-    try:
-        raise Exception('foo')
-    except Exception:
-        exc_type, exc_value, tb = sys.exc_info()
 
     req = get_request()
     pub._set_request(req)
diff --git a/tests/test_rootdirectory.py b/tests/test_rootdirectory.py
index efb4ec5a..f72bf034 100644
--- a/tests/test_rootdirectory.py
+++ b/tests/test_rootdirectory.py
@@ -82,7 +82,7 @@ def test_private_site_anonymous_access():
     formdef1.store()
     formdef2.store()
     with pytest.raises(wcs.forms.root.errors.AccessUnauthorizedError):
-        output = indexhtml()
+        indexhtml()
 
 
 def test_semi_private_site_anonymous_access():
@@ -113,7 +113,7 @@ def test_private_site_unauthorized_access():
     formdef1.store()
     formdef2.store()
     with pytest.raises(wcs.forms.root.errors.AccessUnauthorizedError):
-        output = indexhtml(user2)
+        indexhtml(user2)
 
 
 def test_private_site_semi_authorized_access():
diff --git a/tests/test_saml_auth.py b/tests/test_saml_auth.py
index 56328499..6de1f827 100644
--- a/tests/test_saml_auth.py
+++ b/tests/test_saml_auth.py
@@ -237,7 +237,7 @@ def test_saml_public_key(pub):
 def test_assertion_consumer(pub):
     req = get_assertion_consumer_request(pub)
     saml2 = Saml2Directory()
-    body = saml2.assertionConsumerPost()
+    saml2.assertionConsumerPost()
 
     assert req.response.status_code == 303
     assert req.response.headers['location'] == 'http://example.net'
@@ -247,7 +247,7 @@ def test_assertion_consumer(pub):
 def test_assertion_consumer_unspecified(pub):
     req = get_assertion_consumer_request(pub, ni_format=lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED)
     saml2 = Saml2Directory()
-    body = saml2.assertionConsumerPost()
+    saml2.assertionConsumerPost()
 
     assert req.response.status_code == 303
     assert req.response.headers['location'] == 'http://example.net'
@@ -321,8 +321,7 @@ def test_assertion_consumer_redirect_after_url(pub):
     req = get_assertion_consumer_request(pub)
     req.form['RelayState'] = '/foobar/?test=ok'
     saml2 = Saml2Directory()
-    saml_response_body = req.form['SAMLResponse']
-    body = saml2.assertionConsumerPost()
+    saml2.assertionConsumerPost()
     assert req.response.status_code == 303
     assert req.response.headers['location'] == 'http://example.net/foobar/?test=ok'
 
@@ -331,8 +330,7 @@ def test_assertion_consumer_full_url_redirect_after_url(pub):
     req = get_assertion_consumer_request(pub)
     req.form['RelayState'] = 'http://example.net/foobar/?test=ok'
     saml2 = Saml2Directory()
-    saml_response_body = req.form['SAMLResponse']
-    body = saml2.assertionConsumerPost()
+    saml2.assertionConsumerPost()
     assert req.response.status_code == 303
     assert req.response.headers['location'] == 'http://example.net/foobar/?test=ok'
 
@@ -341,9 +339,8 @@ def test_assertion_consumer_external_url_redirect_after_url(pub):
     req = get_assertion_consumer_request(pub)
     req.form['RelayState'] = 'http://example.org/foobar/?test=ok'
     saml2 = Saml2Directory()
-    saml_response_body = req.form['SAMLResponse']
     with pytest.raises(RequestError):
-        body = saml2.assertionConsumerPost()
+        saml2.assertionConsumerPost()
 
 
 def test_saml_login_page(pub):
@@ -452,7 +449,7 @@ def test_saml_logout(pub):
     saml2 = Saml2Directory()
     saml2.assertionConsumerPost()
     assert req.session.user is not None
-    body = saml2.slo_sp()
+    saml2.slo_sp()
     assert req.response.headers['location'].startswith('http://sso.example.net/saml2/slo?SAMLRequest=')
     assert 'rsa-sha256' in req.response.headers['location']
     assert req.session.user is None
diff --git a/tests/test_sql.py b/tests/test_sql.py
index 96c15183..1bb14497 100644
--- a/tests/test_sql.py
+++ b/tests/test_sql.py
@@ -65,7 +65,7 @@ def test_sql_table_name_invalid_chars():
 
 @postgresql
 def test_sql_data_class():
-    data_class = formdef.data_class(mode='sql')
+    formdef.data_class(mode='sql')
 
 
 @postgresql
@@ -365,7 +365,6 @@ def test_sql_get_ids_with_indexed_value():
 
     formdata = data_class()
     formdata.store()
-    id1 = formdata.id
 
     formdata = data_class()
     formdata.user_id = '2'
@@ -426,7 +425,6 @@ def test_sql_get_ids_with_indexed_value_dict():
 
     formdata = data_class()
     formdata.store()
-    id1 = formdata.id
 
     formdata = data_class()
     formdata.workflow_roles = {'plop': '2'}
@@ -506,7 +504,6 @@ def test_get_users_with_role():
     user.name = 'Pierre'
     user.roles = [1]
     user.store()
-    user_id = user.id
 
     user = sql.SqlUser()
     user.name = 'Papier'
@@ -523,7 +520,6 @@ def test_get_users_with_name_identifier():
     user.name = 'Pierre'
     user.name_identifiers = ['foo']
     user.store()
-    user_id = user.id
 
     user = sql.SqlUser()
     user.name = 'Papier'
@@ -713,7 +709,7 @@ def test_sql_table_select():
     data_class = test_formdef.data_class(mode='sql')
     assert data_class.count() == 0
 
-    for i in range(50):
+    for _ in range(50):
         t = data_class()
         t.store()
 
@@ -744,7 +740,7 @@ def test_sql_table_select_iterator():
     data_class = test_formdef.data_class(mode='sql')
     assert data_class.count() == 0
 
-    for i in range(50):
+    for _ in range(50):
         t = data_class()
         t.store()
 
@@ -809,7 +805,7 @@ def test_select_limit_offset():
     data_class = test_formdef.data_class(mode='sql')
     assert data_class.count() == 0
 
-    for i in range(50):
+    for _ in range(50):
         t = data_class()
         t.store()
 
@@ -872,7 +868,7 @@ def test_count():
     data_class = test_formdef.data_class(mode='sql')
     assert data_class.count() == 0
 
-    for i in range(50):
+    for _ in range(50):
         t = data_class()
         t.store()
 
@@ -889,7 +885,7 @@ def test_select_criteria_or_and():
     data_class = test_formdef.data_class(mode='sql')
     assert data_class.count() == 0
 
-    for i in range(50):
+    for _ in range(50):
         t = data_class()
         t.store()
 
@@ -935,7 +931,7 @@ def test_sql_table_select_bool():
     data_class = test_formdef.data_class(mode='sql')
     assert data_class.count() == 0
 
-    for i in range(50):
+    for _ in range(50):
         t = data_class()
         t.data = {'3': False}
         t.store()
@@ -1328,7 +1324,7 @@ def test_migration_38_user_deleted():
 
 
 def drop_formdef_tables():
-    conn, cur = sql.get_connection_and_cursor()
+    _, cur = sql.get_connection_and_cursor()
     cur.execute('''SELECT table_name FROM information_schema.tables''')
     table_names = []
     while True:
@@ -1344,11 +1340,11 @@ def drop_formdef_tables():
 @postgresql
 def test_is_at_endpoint():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
+    _, cur = sql.get_connection_and_cursor()
 
     wf = Workflow(name='test endpoint')
     st1 = wf.add_status('Status1', 'st1')
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status2', 'st2')
 
     commentable = CommentableWorkflowStatusItem()
     commentable.id = '_commentable'
@@ -1393,7 +1389,7 @@ def test_is_at_endpoint():
 @postgresql
 def test_views_fts():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
+    _, cur = sql.get_connection_and_cursor()
 
     formdef = FormDef()
     formdef.name = 'test fts'
@@ -1421,7 +1417,6 @@ def test_views_fts():
 @postgresql
 def test_select_any_formdata():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
 
     now = datetime.datetime.now()
 
@@ -1482,7 +1477,6 @@ def test_select_any_formdata():
 @postgresql
 def test_load_all_evolutions_on_any_formdata():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
 
     now = datetime.datetime.now()
 
@@ -1514,9 +1508,6 @@ def test_load_all_evolutions_on_any_formdata():
 @postgresql
 def test_geoloc_in_global_view():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
-
-    now = datetime.datetime.now()
 
     formdef = FormDef()
     formdef.name = 'test no geoloc'
@@ -1558,11 +1549,11 @@ def test_geoloc_in_global_view():
 @postgresql
 def test_actions_roles():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
+    _, cur = sql.get_connection_and_cursor()
 
     wf = Workflow(name='test endpoint')
     st1 = wf.add_status('Status1', 'st1')
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status2', 'st2')
 
     commentable = CommentableWorkflowStatusItem()
     commentable.id = '_commentable'
@@ -1624,7 +1615,7 @@ def test_actions_roles():
 @postgresql
 def test_last_update_time():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
+    _, cur = sql.get_connection_and_cursor()
 
     wf = Workflow(name='test last update time')
     st1 = wf.add_status('Status1', 'st1')
@@ -1674,7 +1665,7 @@ def test_last_update_time():
 @postgresql
 def test_view_formdef_name():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
+    _, cur = sql.get_connection_and_cursor()
 
     formdef1 = FormDef()
     formdef1.name = 'test formdef name 1'
@@ -1709,7 +1700,7 @@ def test_view_formdef_name():
 @postgresql
 def test_view_user_name():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
+    _, cur = sql.get_connection_and_cursor()
 
     formdef1 = FormDef()
     formdef1.name = 'test user name'
@@ -1742,11 +1733,8 @@ def test_view_user_name():
 @postgresql
 def test_select_formdata_after_formdef_removal():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
 
-    now = datetime.datetime.now()
-
-    for i in range(2):
+    for _ in range(2):
         formdef = FormDef()
         formdef.name = 'test formdef removal'
         formdef.fields = []
@@ -1770,7 +1758,7 @@ def test_select_formdata_after_formdef_removal():
 @postgresql
 def test_views_submission_info():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
+    _, cur = sql.get_connection_and_cursor()
 
     formdef = FormDef()
     formdef.name = 'test backoffice submission'
@@ -1818,7 +1806,6 @@ def test_get_formdef_new_id():
 @postgresql
 def test_criticality_levels():
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
 
     workflow1 = Workflow(name='criticality1')
     workflow1.criticality_levels = [
@@ -1875,8 +1862,6 @@ def test_view_performances():
     pytest.skip('takes too much time')
 
     drop_formdef_tables()
-    conn, cur = sql.get_connection_and_cursor()
-
     nb_users = 1000
     nb_roles = 10
     nb_workflows = 5
@@ -1964,7 +1949,7 @@ def test_view_performances():
     criterias.append(st.NotEqual('status', 'draft'))
     criterias.append(st.Equal('is_at_endpoint', False))
     criterias.append(st.Intersects('actions_roles_array', user_roles))
-    formdatas = sql.AnyFormData.select(criterias, order_by='receipt_time', limit=20, offset=0)
+    sql.AnyFormData.select(criterias, order_by='receipt_time', limit=20, offset=0)
     print(time.time() - t0)
     assert (time.time() - t0) < 0.5
 
diff --git a/tests/test_storage.py b/tests/test_storage.py
index ff0d2606..d8846d57 100644
--- a/tests/test_storage.py
+++ b/tests/test_storage.py
@@ -255,7 +255,7 @@ def test_select_datetime():
 def test_select_limit_offset():
     Foobar.wipe()
 
-    for x in range(50):
+    for _ in range(50):
         test = Foobar()
         test.store()
 
@@ -384,7 +384,7 @@ def test_store_async():
 def test_items():
     Foobar.wipe()
 
-    for x in range(50):
+    for _ in range(50):
         test = Foobar()
         test.store()
 
@@ -394,7 +394,7 @@ def test_items():
 def test_reversed_order():
     Foobar.wipe()
 
-    for x in range(50):
+    for _ in range(50):
         test = Foobar()
         test.store()
 
@@ -427,7 +427,7 @@ def test_concurrent_hashed_indexes():
         if pid:
             children_pids.append(pid)
         else:
-            for j in range(10):
+            for _ in range(10):
                 test = Foobar()
                 test.value = 'x'
                 test.dict_value = {'plop': random.randint(0, 10)}
diff --git a/tests/test_users.py b/tests/test_users.py
index 3518aa17..ab5b72a2 100644
--- a/tests/test_users.py
+++ b/tests/test_users.py
@@ -26,7 +26,6 @@ def test_get_users_with_name_identifier():
     user.name = 'Pierre'
     user.name_identifiers = ['foo']
     user.store()
-    user_id = user.id
 
     user = pub.user_class()
     user.name = 'Papier'
@@ -62,7 +61,6 @@ def test_get_users_with_role():
     user.name = 'Pierre'
     user.roles = [1]
     user.store()
-    user_id = user.id
 
     user = pub.user_class()
     user.name = 'Papier'
diff --git a/tests/test_widgets.py b/tests/test_widgets.py
index ca16d7c8..aabe239f 100644
--- a/tests/test_widgets.py
+++ b/tests/test_widgets.py
@@ -163,7 +163,6 @@ def test_table_list_rows_add_row():
 def test_table_list_rows_required():
     req.form = {}
     widget = TableListRowsWidget('test', columns=['a', 'b', 'c'], required=True)
-    form = MockHtmlForm(widget)
     mock_form_submission(req, widget)
     widget = TableListRowsWidget('test', columns=['a', 'b', 'c'], required=True)
     assert widget.has_error()
@@ -624,7 +623,6 @@ def test_composite_widget():
     widget.add(StringWidget, name='str1')
     widget.add(StringWidget, name='str2', required=True)
     req.form = {'compotest$str1': 'foo1', 'compotest$str2': 'foo2'}
-    form = MockHtmlForm(widget)
     assert not widget.has_error()
     assert len(widget.widgets) == 2
     assert widget.widgets[0].parse() == 'foo1'
@@ -634,7 +632,6 @@ def test_composite_widget():
     widget.add(StringWidget, name='str1')
     widget.add(StringWidget, name='str2', required=True)
     req.form = {'compotest$str1': 'alone'}
-    form = MockHtmlForm(widget)
     assert widget.has_error()
     assert not widget.widgets[0].has_error()
     assert widget.widgets[0].parse() == 'alone'
@@ -652,13 +649,11 @@ def test_composite_widget():
 
 def test_computed_expression_widget():
     widget = ComputedExpressionWidget('test')
-    form = MockHtmlForm(widget)
     mock_form_submission(req, widget, {'test$value_text': 'hello world', 'test$type': ['text']})
     assert widget.parse() == 'hello world'
     assert not widget.has_error()
 
     widget = ComputedExpressionWidget('test')
-    form = MockHtmlForm(widget)
     mock_form_submission(req, widget, {'test$value_text': '', 'test$type': ['text']})
     assert widget.parse() == None
     assert not widget.has_error()
diff --git a/tests/test_workflow_import.py b/tests/test_workflow_import.py
index 1addd2f3..865f539c 100644
--- a/tests/test_workflow_import.py
+++ b/tests/test_workflow_import.py
@@ -69,15 +69,15 @@ def test_empty(pub):
 
 def test_status(pub):
     wf = Workflow(name='status')
-    st1 = wf.add_status('Status1', 'st1')
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status1', 'st1')
+    wf.add_status('Status2', 'st2')
     assert_import_export_works(wf)
 
 
 def test_status_actions(pub):
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status2', 'st2')
 
     commentable = CommentableWorkflowStatusItem()
     commentable.id = '_commentable'
@@ -93,7 +93,7 @@ def test_status_colour_css_class(pub):
     st1 = wf.add_status('Status1', 'st1')
     st1.extra_css_class = 'hello'
     st1.colour = 'FF0000'
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status2', 'st2')
     assert_import_export_works(wf)
 
 
@@ -101,7 +101,7 @@ def test_status_forced_endpoint(pub):
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
     st1.forced_endpoint = True
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status2', 'st2')
     wf2 = assert_import_export_works(wf)
     assert wf2.possible_status[0].forced_endpoint is True
     assert wf2.possible_status[1].forced_endpoint is False
@@ -161,7 +161,7 @@ def test_action_dispatch(pub):
 def test_status_actions_named_role(pub):
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status2', 'st2')
 
     commentable = CommentableWorkflowStatusItem()
     commentable.id = '_commentable'
@@ -180,7 +180,7 @@ def test_status_actions_named_existing_role(pub):
 
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status2', 'st2')
 
     commentable = CommentableWorkflowStatusItem()
     commentable.id = '_commentable'
@@ -217,7 +217,7 @@ def test_status_actions_named_missing_role(pub):
 
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status2', 'st2')
 
     commentable = CommentableWorkflowStatusItem()
     commentable.id = '_commentable'
@@ -225,7 +225,7 @@ def test_status_actions_named_missing_role(pub):
     st1.items.append(commentable)
     commentable.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    assert_import_export_works(wf)
 
     # check that role name has precedence over id
     xml_export_orig = ET.tostring(export_to_indented_xml(wf))
@@ -339,7 +339,7 @@ def test_export_roles(pub):
 def test_jump_action(pub):
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
-    st2 = wf.add_status('Status2', 'st2')
+    wf.add_status('Status2', 'st2')
 
     jump = JumpWorkflowStatusItem()
     jump.id = '_jump'
@@ -518,7 +518,7 @@ def test_backoffice_fields(pub):
     wf.backoffice_fields_formdef.fields = [
         StringField(id='bo1', label='1st backoffice field', type='string', varname='backoffice_blah'),
     ]
-    wf2 = assert_import_export_works(wf, True)
+    assert_import_export_works(wf, True)
 
 
 def test_complex_dispatch_action(pub):
diff --git a/tests/test_workflows.py b/tests/test_workflows.py
index 291f2cbe..ddcfb4a3 100644
--- a/tests/test_workflows.py
+++ b/tests/test_workflows.py
@@ -331,7 +331,7 @@ def test_jump_count_condition(pub):
     item.condition = {'type': 'python', 'value': 'form_objects.count < 2'}
     assert item.must_jump(formdata) is True
 
-    for i in range(10):
+    for _ in range(10):
         formdata = formdef.data_class()()
         formdata.store()
 
@@ -1670,7 +1670,7 @@ def test_webservice_call(http_requests, pub):
 
     wf = Workflow(name='wf1')
     st1 = wf.add_status('Status1', 'st1')
-    sterr = wf.add_status('StatusErr', 'sterr')
+    wf.add_status('StatusErr', 'sterr')
     wf.store()
 
     FormDef.wipe()
@@ -2351,8 +2351,8 @@ def test_webservice_with_complex_data(http_requests, pub):
     pub.substitutions.feed(MockSubstitutionVariables())
 
     wf = Workflow(name='wf1')
-    st1 = wf.add_status('Status1', 'st1')
-    sterr = wf.add_status('StatusErr', 'sterr')
+    wf.add_status('Status1', 'st1')
+    wf.add_status('StatusErr', 'sterr')
     wf.store()
 
     datasource = {
@@ -2469,7 +2469,7 @@ def test_webservice_with_complex_data(http_requests, pub):
 def test_timeout(two_pubs):
     workflow = Workflow(name='timeout')
     st1 = workflow.add_status('Status1', 'st1')
-    st2 = workflow.add_status('Status2', 'st2')
+    workflow.add_status('Status2', 'st2')
 
     jump = JumpWorkflowStatusItem()
     jump.id = '_jump'
@@ -2508,7 +2508,7 @@ def test_timeout(two_pubs):
 def test_legacy_timeout(pub):
     workflow = Workflow(name='timeout')
     st1 = workflow.add_status('Status1', 'st1')
-    st2 = workflow.add_status('Status2', 'st2')
+    workflow.add_status('Status2', 'st2')
 
     jump = TimeoutWorkflowStatusItem()
     jump.id = '_jump'
@@ -2579,7 +2579,7 @@ def test_timeout_then_remove(two_pubs):
 def test_timeout_with_mark(two_pubs):
     workflow = Workflow(name='timeout')
     st1 = workflow.add_status('Status1', 'st1')
-    st2 = workflow.add_status('Status2', 'st2')
+    workflow.add_status('Status2', 'st2')
 
     jump = JumpWorkflowStatusItem()
     jump.id = '_jump'
@@ -3679,7 +3679,7 @@ def test_global_timeouts(two_pubs):
         WorkflowCriticalityLevel(name='red'),
     ]
     action = workflow.add_global_action('Timeout Test')
-    item = action.append_item('modify_criticality')
+    action.append_item('modify_criticality')
     trigger = action.append_trigger('timeout')
     trigger.anchor = 'creation'
     workflow.store()
@@ -3950,7 +3950,7 @@ def test_global_timeouts_latest_arrival(two_pubs):
         WorkflowCriticalityLevel(name='red'),
     ]
     action = workflow.add_global_action('Timeout Test')
-    item = action.append_item('modify_criticality')
+    action.append_item('modify_criticality')
     trigger = action.append_trigger('timeout')
     trigger.anchor = 'latest-arrival'
     trigger.anchor_status_latest = 'wf-new'
@@ -6110,7 +6110,7 @@ def test_call_external_workflow_with_data_sourced_object(two_pubs):
     carddata.store()
 
     wf = Workflow(name='External actions')
-    st1 = wf.add_status('Action')
+    wf.add_status('Action')
 
     update_global_action = wf.add_global_action('Update linked object data')
     update_action = update_global_action.append_item('external_workflow_global_action')
@@ -6548,7 +6548,7 @@ def test_edit_carddata_with_data_sourced_object(pub):
     # reset data
     for expression in ('=None', '', '""'):
         edit.mappings = [
-            Mapping(field_id='2', expression='=None'),
+            Mapping(field_id='2', expression=expression),
         ]
         wf.store()
 
@@ -6559,7 +6559,7 @@ def test_edit_carddata_with_data_sourced_object(pub):
         formdata.perform_workflow()
 
         carddata = carddef.data_class().select()[0]
-        assert carddata.data['2'] is None
+        assert carddata.data['2'] in [None, '', '""']
         assert carddata.data.get('2_display') is None
         assert carddata.data.get('2_structured') is None
 
diff --git a/tests/utilities.py b/tests/utilities.py
index 9dba17c1..f74345f4 100644
--- a/tests/utilities.py
+++ b/tests/utilities.py
@@ -159,7 +159,7 @@ def create_temporary_pub(sql_mode=False, templates_mode=False, lazy_mode=False):
                 cur = conn.cursor()
                 cur.execute('CREATE DATABASE %s' % dbname)
                 break
-            except psycopg2.Error as e:
+            except psycopg2.Error:
                 if i < 5:
                     i += 1
                     continue
@@ -344,7 +344,7 @@ class HttpRequestsMocking(object):
             {'url': url, 'method': method, 'body': body, 'headers': headers, 'timeout': timeout}
         )
 
-        scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(url)
+        scheme, netloc, path = urllib.parse.urlparse(url)[:3]
         base_url = urllib.parse.urlunparse((scheme, netloc, path, '', '', ''))
 
         with open(os.path.join(os.path.dirname(__file__), 'idp_metadata.xml')) as fd:
-- 
2.30.2

