Bug 34152 - Tests in t/db_dependent/Koha/Item.t fail
Summary: Tests in t/db_dependent/Koha/Item.t fail
Status: RESOLVED INVALID
Alias: None
Product: Koha
Classification: Unclassified
Component: Test Suite (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Emmi Takkinen
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-29 11:44 UTC by Emmi Takkinen
Modified: 2023-12-22 06:22 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 34152: Fix failing t/db_dependent/Koha/Item.t tests (2.41 KB, patch)
2023-07-03 11:52 UTC, Emmi Takkinen
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Emmi Takkinen 2023-06-29 11:44:27 UTC
Runnins prove t/db_dependent/Koha/Item.t leads to following error:

t/db_dependent/Koha/Item.t .. 13/29     # Looks like you planned 15 tests but ran 5.
t/db_dependent/Koha/Item.t .. 15/29 
#   Failed test 'deletion'
#   at t/db_dependent/Koha/Item.t line 998.
Can't call method "can_edit_items_from" on an undefined value at /home/emmi/Koha/Koha/Item.pm line 298.
# Looks like your test exited with 255 just after 15.
t/db_dependent/Koha/Item.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 15/29 subtests 

It seems this happens because we don't mock user enviroment for test patron. However after fixing this issue tests still fail:

t/db_dependent/Koha/Item.t .. 14/29 encountered object 'Koha::Library=HASH(0x55f674e55708)', but neither allow_blessed, convert_blessed nor allow_tags settings are enabled (or TO_JSON/FREEZE method missing) at /home/emmi/Koha/Koha/BackgroundJob.pm line 107.
    # Looks like you planned 15 tests but ran 5.

#   Failed test 'deletion'
#   at t/db_dependent/Koha/Item.t line 999.
Can't call method "biblionumber" on an undefined value at /home/emmi/Koha/t/lib/TestBuilder.pm line 193.
# Looks like your test exited with 255 just after 15.
t/db_dependent/Koha/Item.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 15/29 subtests
Comment 1 Emmi Takkinen 2023-07-03 11:52:38 UTC
Created attachment 152927 [details] [review]
Bug 34152: Fix failing t/db_dependent/Koha/Item.t tests

This patch fixes following issues in t/db_dependent/Koha/Item.t
tests:
- "Can't call method "can_edit_items_from" on an undefined value
at .../Koha/Item.pm line 298." with sending patron data to mocked
environment
- "holds tests" test failures due "not_same_branch" errors by mocking
IndependentBranches enabled and adding mock user environment

To test:
1. Run prove t/db_dependent/Koha/Item.t.
=> Tests should fail.
2. Apply this patch.
3. Run prove t/db_dependent/Koha/Item.t again.
=> Success!

Sponsored-by: Koha-Suomi Oy
Comment 2 Lucas Gass 2023-07-06 22:28:38 UTC
Emmi,

Is there something extra that has to be done to make these tests fail? I cannot make them fail.
Comment 3 Emmi Takkinen 2023-07-07 05:26:41 UTC
(In reply to Lucas Gass from comment #2)
> Emmi,
> 
> Is there something extra that has to be done to make these tests fail? I
> cannot make them fail.

There shouldn't be. I'm using current master and without this patch, test fail to that "Can't call method "can_edit_items_from" on an undefined value" error. I also checked my database, there shouldn't be anything there causing this (extra constraint etc.). This could be a case of randomly failing tests, but running prove t/db_dependent/Koha/Item.t consistently fails on my environment. So that might not be the reason.
Comment 4 Sam Lau 2023-07-07 15:00:06 UTC
Oddly enough, I also can't get it to fail. I ran it 5 times and it passed every time. This is especially weird since tests were failing for me and Lucas on Bug 12133, but it wasn't initially failing for you
Comment 5 Emmi Takkinen 2023-08-07 12:30:29 UTC
(In reply to Sam Lau from comment #4)
> Oddly enough, I also can't get it to fail. I ran it 5 times and it passed
> every time. This is especially weird since tests were failing for me and
> Lucas on Bug 12133, but it wasn't initially failing for you

I actually managed to "can_edit_items_from" problem by changing one of my test borrowers borrowernumber to 51 (which is the borrowernumber of mock patron created with sub mock_userenv). I also had to set him as superlibrarian to prevent "holds tests" from failing. Could it be that sub mock_userenv doesn't work properly?
Comment 6 David Nind 2023-08-08 06:42:26 UTC
Like the other earlier comments, the tests pass for me using koha-testing-docker (KTD) before trying to apply the patch. (The patch still applies successfully).

I've changed the status to Failed QA - happy to retest if you could identify what settings/changes to make to get it to fail.
Comment 7 Emmi Takkinen 2023-12-22 06:22:55 UTC
Tests no longer fail. Setting status as "RESOLVED INVALID".