BadSchemaError - cannot define an empty value in test - either give it a value or explicitly set it to None
See original GitHub issueI am not sure why this exception is raised and there is proper exception message to traceback. Please improve relevant exception message block. I have defined my tavern test valid only.
external function
def generate_request_headers():
"""
Generate the request headers based upon the parse_env_file_to_dict() ouput when headers.env file is passed
:return: header_info as dict
"""
# Set environment variables
# os.environ['ENV_TYPE'] = 'api_gateway'
auth_header = None
if os.environ['ENV_TYPE'] == 'api_gateway':
header_dict = parse_env_file_to_dict() # this method will input as .env and form the headers info as dict
auth_header = {key.strip(): value.strip() for key,value in header_dict.items()}
else:
auth_header = {"Accept": "application/json"}
return Box(auth_header)
Tavern Test:
test_name: Verify healthz API request and 200 status code
marks:
- smoke
- regression
- health
stages:
- name: Check AI_Get_Similar_Nodes API Request
request:
url: "{tavern.env_vars.HOST_IP:s}{apiInfo.health_check:s}"
method: GET
headers:
$ext:
function: notifications.test_utilities.helpers:generate_request_headers
response:
status_code: 200
json:
status: ok from notification #API output is {"status":"ok from notification"}
---
run.sh
#!/usr/bin/env bash
host_ip_fetched=$1
env_type_fetched=$2
export HOST_IP=${host_ip_fetched:-"http://localhost:5003"}
export ENV_TYPE=${env_type_fetched:-"local"}
pytest -vv tests/positive
======================================================================= test session starts ========================================================================
platform win32 -- Python 3.8.3, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- c:\venkatesh\gitlab_push\hps-api-tavern-tests\venv\scripts\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.8.3', 'Platform': 'Windows-10-10.0.16299-SP0', 'Packages': {'pytest': '6.1.1', 'py': '1.9.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '2.1.1
', 'metadata': '1.10.0', 'tavern': '1.6.0'}, 'JAVA_HOME': 'C:\\Program Files\\java\\jdk-12.0.2'}
rootdir: C:\Venkatesh\gitlab_push\hps-api-tavern-tests\notifications, configfile: pytest.ini
plugins: html-2.1.1, metadata-1.10.0, tavern-1.6.0
collected 0 items / 1 error
============================================================================== ERRORS ==============================================================================
______________________________________________ ERROR collecting tests/positive/test_Notification_Healthz.tavern.yaml _______________________________________________
..\venv\lib\site-packages\tavern\testutils\pytesthook\file.py:274: in collect
all_tests = list(
..\venv\lib\site-packages\yaml\__init__.py:130: in load_all
yield loader.get_data()
..\venv\lib\site-packages\yaml\constructor.py:45: in get_data
return self.construct_document(self.get_node())
..\venv\lib\site-packages\yaml\composer.py:27: in get_node
return self.compose_document()
..\venv\lib\site-packages\tavern\util\loader.py:38: in compose_document
node = self.compose_node(None, None)
..\venv\lib\site-packages\yaml\composer.py:64: in compose_node
if self.check_event(AliasEvent):
..\venv\lib\site-packages\yaml\parser.py:98: in check_event
self.current_event = self.state()
..\venv\lib\site-packages\yaml\parser.py:211: in parse_document_content
event = self.process_empty_scalar(self.peek_token().start_mark)
..\venv\lib\site-packages\tavern\util\loader.py:423: in error_on_empty_scalar
raise exceptions.BadSchemaError(error)
E tavern.util.exceptions.BadSchemaError: Error at C:\Venkatesh\gitlab_push\hps-api-tavern-tests\notifications\tests\positive\test_Notification_Healthz.tavern.yaml:
19 - column 3 - cannot define an empty value in test - either give it a value or explicitly set it to None
===================================================================== short test summary info ======================================================================
ERROR tests/positive/test_Notification_Healthz.tavern.yaml - tavern.util.exceptions.BadSchemaError: Error at C:\Venkatesh\gitlab_push\hps-api-tavern-tests\notific...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================================= 1 error in 1.44s =========================================================================
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
'cannot define an empty value in test' · Issue #407 - GitHub
Getting 'BadSchemaError cannot define an empty value in test - either give it a value or explicitly set it to None' at the...
Read more >BadSchemaError - cannot define an empty value in test
BadSchemaError - cannot define an empty value in test - either give it a value or explicitly set it to None.
Read more >How to validate YAML schema for Python/Tavern
It means writing a program (API test) in YAML. Problem is, when I edit YAML input, it often breaks with error BadSchemaError. Tavern...
Read more >How to use the tavern.util.exceptions.BadSchemaError ... - Snyk
To help you get started, we've selected a few tavern.util.exceptions.BadSchemaError examples, based on popular ways it is used in public projects.
Read more >All Reports with description - SQLite CVSTrac
In order to do this, we would have to either run the query twice or load the entire result set into memory. Otherwise,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@benhowes , Finally found the rootcause of the exception is Pycharm IDE is not loading or parsing the yaml file perfectly. I have saved the same set of code with NotePad++, then code is executing perfectly.
Thanks you so much for your reply. Keep doing your good work.
Glad to hear its solved, I’ve had a few issues with indentation in yaml files where its not obvious why something isn’t working before.