-
Notifications
You must be signed in to change notification settings - Fork 400
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
Unit tests of example do not pass #24
Labels
bug
Something isn't working
Comments
Thanks for reporting it!
Your assessment is spot on. I believe you were trying to run the tests for
the example inside the project - Correct me I’m wrong, and you used a fresh
new project instead.
For tests to work correctly without a metric namespace, we have to either
set the namespace explicitly, or to use pytest monkeypatch.setenv(..) as
part of the test.
I’ll get it fixed later today.
Thanks again
…On Sun, 26 Apr 2020 at 23:12, Nxtra ***@***.***> wrote:
*Current behaviour*
I followed the instructions in the README and installed the dependencies
in a virtual environment
pip install -r hello_world/requirements.txt && pip install -r requirements-dev.txt
Then I run the tests with : POWERTOOLS_TRACE_DISABLED=1 python -m pytest.
The test fails with output:
FAILED tests/unit/test_handler.py::test_lambda_handler -
aws_lambda_powertools.metrics.exceptions.SchemaValidationError: Invalid
format. Error: data._aws.CloudWatchMetrics[0].Namespace must be string,
Invalid item: data._aws.CloudWatchMetrics[0...
( I can provide a full stacktrace if necessary)
*Potential solution*
I looked into base.py of the aws_lambda_powertools metrics package and
found that it is looking for an env var POWERTOOLS_METRICS_NAMESPACE.
This env var is not there when running the tests.
First setting the env var and then running it solves the issue:
POWERTOOLS_TRACE_DISABLED=1 POWERTOOLS_METRICS_NAMESPACE=test python -m
pytest tests -v
If my assessment is correct, I propose to update the README. If incorrect
can you help me by determining what is causing this problem?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<aws-powertools/powertools-lambda#24>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZPQBFZ3GIHSOEZZ3W7KO3ROSWWHANCNFSM4MRNWNFQ>
.
|
@Nxtra - Just pushed a fix to Updates to the READMERelevant and updated part in bold
Updates to the testWe now capture the stdout, and assert if our custom middleware and metrics were correct: def test_lambda_handler(apigw_event, mocker, capsys):
...
output = capsys.readouterr()
output = output.out.split('\n')
stdout_one_string = '\t'.join(output)
...
# assess custom metric was flushed in stdout/logs
assert "SuccessfulLocations" in stdout_one_string
assert "ColdStart" in stdout_one_string
assert "UniqueMetricDimension" in stdout_one_string
# assess our custom middleware ran
assert "Logging response after Handler is called" in stdout_one_string
assert "Logging event before Handler is called" in stdout_one_string |
heitorlessa
added a commit
that referenced
this issue
May 16, 2020
* develop: (21 commits) bugfix: #32 Runtime Error for nested sync fns chore: renamed history to changelog dependabot bugfix: resolves #31 aiohttp lazy import chore: grammar issues improv: add project tenets Improv tracer - async support, patch, test coverage and X-Ray escape hatch (#29) Bugfix: "per second" metric units (#27) fix: #24 correct example test and docs chore: bump example to use 0.8.0 features Adopt logging best practices (#23) Decorator factory Feat: Create your own middleware (#17) chore: clean up CI workflows fix: CI attempt 4 fix: CI attempt 3 fix: CI attempt 3 fix: CI attempt 2 feat: add docs to CI chore: fix github badge typo chore: pypi monthly download badge fix: add missing single_metric example; test var name ...
heitorlessa
referenced
this issue
in heitorlessa/aws-lambda-powertools-python
Jun 17, 2020
When running in tests, you could apply it to all tests inside a test case: @patch.dict(os.environ, {
"UNIT_TEST_ENV": "yes",
"POWERTOOLS_METRICS_NAMESPACE": "Example",
"POWERTOOLS_TRACE_DISABLED": "1",
})
class HandlerTestCase(BasicTestCase):
def test_handler(self): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current behaviour
I followed the instructions in the README and installed the dependencies in a virtual environment
Then I run the tests with :
POWERTOOLS_TRACE_DISABLED=1 python -m pytest
.The test fails with output:
FAILED tests/unit/test_handler.py::test_lambda_handler - aws_lambda_powertools.metrics.exceptions.SchemaValidationError: Invalid format. Error: data._aws.CloudWatchMetrics[0].Namespace must be string, Invalid item: data._aws.CloudWatchMetrics[0...
( I can provide a full stacktrace if necessary)
Potential solution
I looked into
base.py
of theaws_lambda_powertools
metrics
package and found that it is looking for an env varPOWERTOOLS_METRICS_NAMESPACE
.This env var is not there when running the tests.
First setting the env var and then running it solves the issue:
POWERTOOLS_TRACE_DISABLED=1 POWERTOOLS_METRICS_NAMESPACE=test python -m pytest tests -v
If my assessment is correct, I propose to update the README. If incorrect can you help me by determining what is causing this problem?
The text was updated successfully, but these errors were encountered: