Test AssertionError: Field method on_change for unknown field

73 views
Skip to first unread message

Jesús Martín Jiménez

unread,
Aug 25, 2016, 4:15:04 AM8/25/16
to tryton
Hi,

I'm testing a customized module and I run into an issue I'm not sure how to resolve. My module has an extras_depend of stock_lot and an on_change method for lot field. It works well, but when I try to pass the unittest test, it fails with this traceback [1]. I'm not sure if it is a bug or the desired behavior.

[1]
FAIL: test_field_methods (trytond.modules.stock_number_of_packages.tests.test_stock_number_of_packages.TestCase)
Test field methods
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jesus/projectes/tryton/.../trytond/trytond/tests/test_tryton.py", line 80, in wrapper
    result = func(*args, **kwargs)
  File "/home/jesus/projectes/tryton/.../trytond/trytond/tests/test_tryton.py", line 201, in test_field_methods
    mname, attr))
AssertionError: Field method "stock.inventory.line"."on_change_lot" for unknown field

Sergi Almacellas Abellana

unread,
Aug 25, 2016, 4:23:01 AM8/25/16
to try...@googlegroups.com
El 25/08/16 a les 10:02, Jesús Martín Jiménez ha escrit:
> Hi,
>
> I'm testing a customized module and I run into an issue I'm not sure how
> to resolve. My module has an extras_depend of stock_lot and an on_change
> method for lot field. It works well, but when I try to pass the unittest
> test, it fails with this traceback [1]. I'm not sure if it is a bug or
> the desired behavior.

For me is the expected behavior if you define the on_change_lot method
when the stock_lot module is not installed.

That can be solved by defining the on_change only if the stock_lot
module is installed, which can be done on the __setup__ method of the
class.

>
> [1]
> FAIL: test_field_methods
> (trytond.modules.stock_number_of_packages.tests.test_stock_number_of_packages.TestCase)
> Test field methods
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File
> "/home/jesus/projectes/tryton/.../trytond/trytond/tests/test_tryton.py",
> line 80, in wrapper
> result = func(*args, **kwargs)
> File
> "/home/jesus/projectes/tryton/.../trytond/trytond/tests/test_tryton.py",
> line 201, in test_field_methods
> mname, attr))
> AssertionError: Field method "stock.inventory.line"."on_change_lot" for
> unknown field
>
> --
> You received this message because you are subscribed to the Google
> Groups "tryton" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/tryton/56ad77e9-c67a-477c-ad96-edb7384977e8%40googlegroups.com
> <https://groups.google.com/d/msgid/tryton/56ad77e9-c67a-477c-ad96-edb7384977e8%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Guillem Barba Domingo

unread,
Aug 25, 2016, 4:56:42 AM8/25/16
to try...@googlegroups.com
2016-08-25 10:22 GMT+02:00 Sergi Almacellas Abellana <se...@koolpi.com>:
El 25/08/16 a les 10:02, Jesús Martín Jiménez ha escrit:
Hi,

I'm testing a customized module and I run into an issue I'm not sure how
to resolve. My module has an extras_depend of stock_lot and an on_change
method for lot field. It works well, but when I try to pass the unittest
test, it fails with this traceback [1]. I'm not sure if it is a bug or
the desired behavior.

For me is the expected behavior if you define the on_change_lot method when the stock_lot module is not installed.

That can be solved by defining the on_change only if the stock_lot module is installed, which can be done on the __setup__ method of the class.

I think it's better to raise a warning instead of an assert exception for this test.
To have an unused method is not an error/crash. For example, pylint defines the "unused param/variable/import" as a warning, not an error.

--

Cédric Krier

unread,
Aug 25, 2016, 5:45:04 AM8/25/16
to try...@googlegroups.com
On 2016-08-25 10:22, Sergi Almacellas Abellana wrote:
> El 25/08/16 a les 10:02, Jesús Martín Jiménez ha escrit:
> >Hi,
> >
> >I'm testing a customized module and I run into an issue I'm not sure how
> >to resolve. My module has an extras_depend of stock_lot and an on_change
> >method for lot field. It works well, but when I try to pass the unittest
> >test, it fails with this traceback [1]. I'm not sure if it is a bug or
> >the desired behavior.
>
> For me is the expected behavior if you define the on_change_lot method when
> the stock_lot module is not installed.
>
> That can be solved by defining the on_change only if the stock_lot module is
> installed, which can be done on the __setup__ method of the class.

This is not very elegant. Indeed I think it will be better to install
the extra_depends in the setupClass.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Guillem Barba Domingo

unread,
Aug 25, 2016, 7:54:52 AM8/25/16
to try...@googlegroups.com
2016-08-25 11:41 GMT+02:00 Cédric Krier <cedric...@b2ck.com>:
On 2016-08-25 10:22, Sergi Almacellas Abellana wrote:
> El 25/08/16 a les 10:02, Jesús Martín Jiménez ha escrit:
> >Hi,
> >
> >I'm testing a customized module and I run into an issue I'm not sure how
> >to resolve. My module has an extras_depend of stock_lot and an on_change
> >method for lot field. It works well, but when I try to pass the unittest
> >test, it fails with this traceback [1]. I'm not sure if it is a bug or
> >the desired behavior.
>
> For me is the expected behavior if you define the on_change_lot method when
> the stock_lot module is not installed.
>
> That can be solved by defining the on_change only if the stock_lot module is
> installed, which can be done on the __setup__ method of the class.

This is not very elegant. Indeed I think it will be better to install
the extra_depends in the setupClass.

The ideal would be to run tests with only the dependencies and also (another execution) with each extra_depends. It will give us the maximum coverage... but provably with an ¿unacceptable? time consumption. 

Sergi Almacellas Abellana

unread,
Aug 25, 2016, 10:02:15 AM8/25/16
to try...@googlegroups.com
El 25/08/16 a les 13:54, Guillem Barba Domingo ha escrit:
> The ideal would be to run tests with only the dependencies and also
> (another execution) with each extra_depends. It will give us the maximum
> coverage... but provably with an ¿unacceptable? time consumption.
>
That's possible if you use two scenarios. One with the minimum
dependencies and other with the extra_depends.

Guillem Barba Domingo

unread,
Aug 26, 2016, 2:58:57 AM8/26/16
to try...@googlegroups.com
2016-08-25 16:02 GMT+02:00 Sergi Almacellas Abellana <se...@koolpi.com>:
El 25/08/16 a les 13:54, Guillem Barba Domingo ha escrit:
The ideal would be to run tests with only the dependencies and also
(another execution) with each extra_depends. It will give us the maximum
coverage... but provably with an ¿unacceptable? time consumption.

That's possible if you use two scenarios. One with the minimum dependencies and other with the extra_depends.

The assert is not raised in the scenarios but in the Unit Test 

Cédric Krier

unread,
Aug 26, 2016, 3:45:03 AM8/26/16
to try...@googlegroups.com
That's why for me you must install the extra_depends in the setUpClass
otherwise you can not test all the methods and views.
I thought ModuleTestCase could do it but it will be complicated compare
to how easy it is to just override setUpClass to do it.

Jesús Martín Jiménez

unread,
Aug 26, 2016, 5:05:12 AM8/26/16
to try...@googlegroups.com
2016-08-26 9:40 GMT+02:00 Cédric Krier <cedric...@b2ck.com>:
On 2016-08-26 08:58, Guillem Barba Domingo wrote:
> 2016-08-25 16:02 GMT+02:00 Sergi Almacellas Abellana <se...@koolpi.com>:
>
> > El 25/08/16 a les 13:54, Guillem Barba Domingo ha escrit:
> >
> >> The ideal would be to run tests with only the dependencies and also
> >> (another execution) with each extra_depends. It will give us the maximum
> >> coverage... but provably with an ¿unacceptable? time consumption.
> >>
> >> That's possible if you use two scenarios. One with the minimum
> > dependencies and other with the extra_depends.
>
>
> The assert is not raised in the scenarios but in the Unit Test

That's why for me you must install the extra_depends in the setUpClass
otherwise you can not test all the methods and views.
I thought ModuleTestCase could do it but it will be complicated compare
to how easy it is to just override setUpClass to do it.

Thanks a lot. It worked for me!
 

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
--
You received this message because you are subscribed to the Google Groups "tryton" group.



--
Jesús Martín Jiménez
Programador
Tel. 935 531 803
Reply all
Reply to author
Forward
0 new messages