Skip to content

Commit

Permalink
Ensure coverage reporting on unexecuted files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marksparkza committed Oct 26, 2022
1 parent d3d2783 commit b6e8962
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
47 changes: 25 additions & 22 deletions odp/identity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@
from odp.config import config
from odp.lib.hydra_admin import HydraAdminClient

mail = Mail()
if config.ODP.ENV != 'testing':
# TODO: test odp.identity...

hydra_admin = HydraAdminClient(
server_url=config.HYDRA.ADMIN.URL,
verify_tls=config.ODP.ENV != 'development',
remember_login_for=config.ODP.IDENTITY.LOGIN_EXPIRY,
)
mail = Mail()

redis_cache = redis.Redis(
host=config.REDIS.HOST,
port=config.REDIS.PORT,
db=config.REDIS.DB,
decode_responses=True,
)
hydra_admin = HydraAdminClient(
server_url=config.HYDRA.ADMIN.URL,
verify_tls=config.ODP.ENV != 'development',
remember_login_for=config.ODP.IDENTITY.LOGIN_EXPIRY,
)

google_oauth2 = OAuth(cache=redis_cache)
google_oauth2.register(
name='google',
authorize_url=config.GOOGLE.AUTH_URI,
access_token_url=config.GOOGLE.TOKEN_URI,
server_metadata_url=config.GOOGLE.OPENID_URI,
client_id=config.GOOGLE.CLIENT_ID,
client_secret=config.GOOGLE.CLIENT_SECRET,
client_kwargs={'scope': ' '.join(config.GOOGLE.SCOPE)},
)
redis_cache = redis.Redis(
host=config.REDIS.HOST,
port=config.REDIS.PORT,
db=config.REDIS.DB,
decode_responses=True,
)

google_oauth2 = OAuth(cache=redis_cache)
google_oauth2.register(
name='google',
authorize_url=config.GOOGLE.AUTH_URI,
access_token_url=config.GOOGLE.TOKEN_URI,
server_metadata_url=config.GOOGLE.OPENID_URI,
client_id=config.GOOGLE.CLIENT_ID,
client_secret=config.GOOGLE.CLIENT_SECRET,
client_kwargs={'scope': ' '.join(config.GOOGLE.SCOPE)},
)
16 changes: 14 additions & 2 deletions test/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
[run]
source = odp
source =
# odp-core
odp.config
odp.const
odp.schema
odp.logfile
odp.version
# odp-server
odp.api
odp.catalog
odp.db
odp.identity
odp.lib

branch = True
omit = */odp/ui/*

[report]
exclude_lines =
Expand Down
22 changes: 22 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@
from odp.config import config


# noinspection PyUnresolvedReferences
@pytest.fixture(scope='session', autouse=True)
def ensure_coverage():
"""Since the codebase now defines `odp` as a namespace package,
coverage cannot discover subpackages and modules that are not
imported during a test run, preventing reporting on unexecuted
files and hence inflating the coverage score. So, we import
everything we want covered here."""
# odp-core
import odp.config
import odp.const
import odp.schema
import odp.logfile
import odp.version
# odp-server
import odp.api
import odp.catalog
import odp.db
import odp.identity
import odp.lib


@pytest.fixture(scope='session', autouse=True)
def database():
"""An auto-use, run-once fixture that provides a clean
Expand Down

0 comments on commit b6e8962

Please sign in to comment.