Skip to content

Commit b6e8962

Browse files
committed
Ensure coverage reporting on unexecuted files
Since `odp` is now a namespace package, coverage cannot discover and report on code that is not actually imported during a test run (see nedbat/coveragepy#1024 for further discussion around this issue). This was giving us an inflated coverage score.
1 parent d3d2783 commit b6e8962

File tree

3 files changed

+61
-24
lines changed

3 files changed

+61
-24
lines changed

odp/identity/__init__.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,31 @@
55
from odp.config import config
66
from odp.lib.hydra_admin import HydraAdminClient
77

8-
mail = Mail()
8+
if config.ODP.ENV != 'testing':
9+
# TODO: test odp.identity...
910

10-
hydra_admin = HydraAdminClient(
11-
server_url=config.HYDRA.ADMIN.URL,
12-
verify_tls=config.ODP.ENV != 'development',
13-
remember_login_for=config.ODP.IDENTITY.LOGIN_EXPIRY,
14-
)
11+
mail = Mail()
1512

16-
redis_cache = redis.Redis(
17-
host=config.REDIS.HOST,
18-
port=config.REDIS.PORT,
19-
db=config.REDIS.DB,
20-
decode_responses=True,
21-
)
13+
hydra_admin = HydraAdminClient(
14+
server_url=config.HYDRA.ADMIN.URL,
15+
verify_tls=config.ODP.ENV != 'development',
16+
remember_login_for=config.ODP.IDENTITY.LOGIN_EXPIRY,
17+
)
2218

23-
google_oauth2 = OAuth(cache=redis_cache)
24-
google_oauth2.register(
25-
name='google',
26-
authorize_url=config.GOOGLE.AUTH_URI,
27-
access_token_url=config.GOOGLE.TOKEN_URI,
28-
server_metadata_url=config.GOOGLE.OPENID_URI,
29-
client_id=config.GOOGLE.CLIENT_ID,
30-
client_secret=config.GOOGLE.CLIENT_SECRET,
31-
client_kwargs={'scope': ' '.join(config.GOOGLE.SCOPE)},
32-
)
19+
redis_cache = redis.Redis(
20+
host=config.REDIS.HOST,
21+
port=config.REDIS.PORT,
22+
db=config.REDIS.DB,
23+
decode_responses=True,
24+
)
25+
26+
google_oauth2 = OAuth(cache=redis_cache)
27+
google_oauth2.register(
28+
name='google',
29+
authorize_url=config.GOOGLE.AUTH_URI,
30+
access_token_url=config.GOOGLE.TOKEN_URI,
31+
server_metadata_url=config.GOOGLE.OPENID_URI,
32+
client_id=config.GOOGLE.CLIENT_ID,
33+
client_secret=config.GOOGLE.CLIENT_SECRET,
34+
client_kwargs={'scope': ' '.join(config.GOOGLE.SCOPE)},
35+
)

test/.coveragerc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
[run]
2-
source = odp
2+
source =
3+
# odp-core
4+
odp.config
5+
odp.const
6+
odp.schema
7+
odp.logfile
8+
odp.version
9+
# odp-server
10+
odp.api
11+
odp.catalog
12+
odp.db
13+
odp.identity
14+
odp.lib
15+
316
branch = True
4-
omit = */odp/ui/*
517

618
[report]
719
exclude_lines =

test/conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77
from odp.config import config
88

99

10+
# noinspection PyUnresolvedReferences
11+
@pytest.fixture(scope='session', autouse=True)
12+
def ensure_coverage():
13+
"""Since the codebase now defines `odp` as a namespace package,
14+
coverage cannot discover subpackages and modules that are not
15+
imported during a test run, preventing reporting on unexecuted
16+
files and hence inflating the coverage score. So, we import
17+
everything we want covered here."""
18+
# odp-core
19+
import odp.config
20+
import odp.const
21+
import odp.schema
22+
import odp.logfile
23+
import odp.version
24+
# odp-server
25+
import odp.api
26+
import odp.catalog
27+
import odp.db
28+
import odp.identity
29+
import odp.lib
30+
31+
1032
@pytest.fixture(scope='session', autouse=True)
1133
def database():
1234
"""An auto-use, run-once fixture that provides a clean

0 commit comments

Comments
 (0)