Skip to content
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

Mock Odoo module for unit tests #75

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

yvaucher
Copy link
Member

@yvaucher yvaucher commented Oct 4, 2024

As Odoo is an heavy piece of software and we don't have to check it runs we can mock the import. For further unit tests, the few methods we use will have to be mocked too.

conftest.py Outdated
@@ -0,0 +1,5 @@
import sys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose github action do not read conftest as CI is using unittest to run tests :-/ (introduce by this commit ea53560#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03fR42)

It seems to be possible to test pytest plugin using pytest, there is also a pytester pluging, not sure we needs it https://docs.pytest.org/en/stable/how-to/writing_plugins.html#testing-plugins so I suppose we needs to change how github action launch tests on CI as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that we were using unittest in the ci.
I think it makes more sense to use pytest to use a pytest mod.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After few testing, I replaced the mock using testconf.py by a setup with tox and a mock module.
This seems to play nicely.

Also had to make few changes to fixup the coverage and codcov config.

@yvaucher yvaucher force-pushed the pytest-mock-odoo branch 3 times, most recently from 39ba1d6 to bc75542 Compare October 4, 2024 20:39
As Odoo is an heavy piece of software and we don't have to check if it runs.
So we can mock the import.
For further unit tests, the few methods we use will have to be mocked too.

Changes in the CI

replaces unittest by pytest
configure codecov
use tox

test pytest addon with pytest

Test with pytester

use pytest-cov

Use tox

fix coverage data collection

xml report for codecov

Set token for codecov

Upgrade GH action codecov to v4
@yvaucher yvaucher merged commit c68bc3d into camptocamp:master Oct 5, 2024
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants