Commit Graph
6 Commits
Author SHA1 Message Date
John Wilson bb1d9e7b26 [FIX] tests/common: Fix tests on Windows and with Debian release
closes odoo/odoo#120297

X-original-commit: 26c6997d8de5679307485cd8efb6b2ce5662f34c
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2023-05-03 12:39:53 +02:00
Xavier-Do e9b170da38 [IMP] tests: refactor unittest classes
Odoo Test environments requires to modify many parts of the unittest
TestCase, Suite and Result.

The main initial reason is to **avoid to postpone result at the end of
the test suite**, because even if it is convenient to have all errors
visible after the tests in some case, odoo logs adds information during
the execution that can be useful to debug when a test fail, to have
context for an error. (see **OdooTestResult**)

We are also fixing the stack trace comming from a unittest and since
there is no proper way to hook inside the TestPartExecutor, a dirty hack
injects anoter result on the outcome to manage the error and complete
the stack trace. This was also a way to avoid to postpone subtest logs
at the end of the test case (see _ErrorCatcher)

`_feedErrorsToResult` was used to test the test suite behavior since
there are many customization and this is quite fragile, especially if
unittest changes behavior in other python version.

**Python 3.11** introduced python/cpython#664448d8 That, in a way, goes
in the same direction of the changed introduced with _ErrorCatcher:
immediately feed errors to resut instead of postponing it. But this also
removes `_feedErrorsToResult` that was used to test this behaviors, as
well as other ones.

Since odoo should remain multi-version, this amount of changes on the
initial behavior become to complicate to keep cross-version and the
(already in our mind for a while) solution to **vendor unittest** will
help to simplify most of our test code base.

This commit modified the vendored unittest files to simplify them as
much as possible to suite our needs.

Since the runner is still the unittest one, we need to inherit from
unittest.Testcase in order to have the right type.

This also means that we still have access to all TestCase methods
without overriding them all. This is convenient for assertion methods as
an example but the initial idea is to vendor our own version of TestCase
to avoid having trouble to adapte our miscommunications to future python
versions. A trade-off must be done to chose what should remain in our
code base. The idea is to keep logic closely linked to our changes in
our code base, mainly around the run method, but also addClassCleanup
wich need to be vendored for python 3.7, but assertions methods are
independent. Any logic can be moved fom unittest to our
vendored version in the future if needed.

X-original-commit: 9a5d1ea54be49e4cc8208c33e76a6bbd2414d5d0
Part-of: odoo/odoo#113850
2023-02-28 23:49:33 +01:00
duongnguyen b17533c9f9 [FIX] base: fix test failing when sources are not in a folder named
'odoo'

-EX: odoo addons path is '~/odoo15/odoo/...' or '~/15.0/odoo/...'
Basically not start with 'odoo' it will get error when running tests
case on this file

closes odoo/odoo#109135

X-original-commit: 336b966f7959b4a5e716b58b25ab13d7e3f92691
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2023-01-06 11:25:02 +01:00
Xavier-Do f842ae07d2 [IMP] tests: make python version accessible without importing sys
closes odoo/odoo#108202

X-original-commit: 27575ed59476238c76d40143d81f6975f1934f7c
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2022-12-16 19:37:53 +01:00
Xavier-Do e583a1f8f4 [FIX] tests: better test traceback
The motivation of this commit is to get a correct pathname on an
ir_logging when a test fail .

The main issue comes from subtest since an exception inside a subtest
will have only a partial traceback, not containing the line triggering
the error in the test method.

This can also affect debugging since a part of the stack is missing.

See pull request for more informations

X-original-commit: 2b6a8bc79529578ecd21bbb0fd4fe452f28d7cd7
Part-of: odoo/odoo#108202
2022-12-16 19:37:52 +01:00
Raphael Collet 8b6232ed25 [FIX] tests: allow OdooSuite to handle unittest.TestCase without crashing
closes odoo/odoo#79713

X-original-commit: 6ae762f1e4a7f3eb5320d28428310905961dfad3
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-11-15 08:18:26 +00:00