Skip to content

Commit

Permalink
Mock Odoo module for unit tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yvaucher committed Oct 5, 2024
1 parent 095ca9f commit edbdd04
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit = tests/*
setup.py
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
pip install tox codecov tox-gh-actions wheel
- name: Generate Report
run: |
pip install coverage
pip install .[test]
coverage run -m unittest
tox run
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # required
21 changes: 17 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
*.egg-info
*.pyc
.cache/
dist/
# Byte-compiled / optimized / DLL
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
build/
dist/
eggs/
.eggs/
*.egg-info/
*.egg

# Unit test / coverage reports
.tox
.coverage
.coverage.*
.cache/
3 changes: 3 additions & 0 deletions tests/mock/odoo/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from mock import MagicMock
registry = MagicMock()
tools = MagicMock()
2 changes: 2 additions & 0 deletions tests/mock/odoo/odoo/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from mock import MagicMock
common = MagicMock()
12 changes: 12 additions & 0 deletions tests/mock/odoo/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import find_packages, setup

setup(
name="odoo",
version="0.0.1",
packages=find_packages(),
package_dir={"odoo": "odoo"},
install_requires="mock"
)
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[testenv]
deps = pytest
pytest-cov
coverage
commands =
pip install tests/mock/odoo
pytest --cov=pytest_odoo . --cov-report=xml

0 comments on commit edbdd04

Please sign in to comment.