Skip to content

Conversation

@flichtenheld
Copy link
Contributor

  • Make tests easier to execute
  • Fix a random test failure related to _get_parameter_string
Now works independently on whether executing pytest in test/ or in the project root dir. While here, moved test_policy global variable to fixtures.
@gsnyder2007 gsnyder2007 self-assigned this Aug 26, 2019
@gsnyder2007
Copy link
Contributor

@flichtenheld thanks for the contributions.

I got an error when attempting to run them locally. Looks like a directory (shared_datadir) didn't get committed? See output including my checkouts to confirm I got the right stuff, below.

(blackduck) gsnyder@gsnyder-mac:~/Projects/hub-rest-api-python-test$ git checkout -b flichtenheld-test-improvements master Switched to a new branch 'flichtenheld-test-improvements' (blackduck) gsnyder@gsnyder-mac:~/Projects/hub-rest-api-python-test$ git pull https://github.com/flichtenheld/hub-rest-api-python.git test-improvements remote: Enumerating objects: 14, done. remote: Counting objects: 100% (14/14), done. remote: Compressing objects: 100% (5/5), done. remote: Total 14 (delta 8), reused 14 (delta 8), pack-reused 0 Unpacking objects: 100% (14/14), done. From https://github.com/flichtenheld/hub-rest-api-python * branch test-improvements -> FETCH_HEAD Auto-merging blackduck/HubRestApi.py Merge made by the 'recursive' strategy. blackduck/HubRestApi.py | 3 ++- requirements.txt | 1 + setup.cfg | 2 ++ setup.py | 2 ++ test/{ => data}/no-roles-roles.json | 0 test/{ => data}/no-roles-user.json | 0 test/{ => data}/policies.json | 0 test/{ => data}/sample-bom-component.json | 0 test/{ => data}/sample-project-versions.json | 0 test/{ => data}/sample-project.json | 0 test/{ => data}/sample-projects-using-name-query.json | 0 test/{ => data}/sample-projects.json | 0 test/{ => data}/sample-snippet-match.json | 0 test/{ => data}/sample-vulnerability.json | 0 test/{ => data}/sysadmin-roles.json | 0 test/{ => data}/sysadmin-user.json | 0 test/{ => data}/unreviewed_snippet.json | 0 test/{ => data}/users.json | 0 test/{ => data}/version.json | 0 test/test_hub_rest_api_python.py | 95 ++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------- 20 files changed, 49 insertions(+), 54 deletions(-) create mode 100644 setup.cfg rename test/{ => data}/no-roles-roles.json (100%) rename test/{ => data}/no-roles-user.json (100%) rename test/{ => data}/policies.json (100%) rename test/{ => data}/sample-bom-component.json (100%) rename test/{ => data}/sample-project-versions.json (100%) rename test/{ => data}/sample-project.json (100%) rename test/{ => data}/sample-projects-using-name-query.json (100%) rename test/{ => data}/sample-projects.json (100%) rename test/{ => data}/sample-snippet-match.json (100%) rename test/{ => data}/sample-vulnerability.json (100%) rename test/{ => data}/sysadmin-roles.json (100%) rename test/{ => data}/sysadmin-user.json (100%) rename test/{ => data}/unreviewed_snippet.json (100%) rename test/{ => data}/users.json (100%) rename test/{ => data}/version.json (100%) (blackduck) gsnyder@gsnyder-mac:~/Projects/hub-rest-api-python-test$ cd test (blackduck) gsnyder@gsnyder-mac:~/Projects/hub-rest-api-python-test/test$ pytest ================================================================================ test session starts ================================================================================ platform darwin -- Python 3.7.0, pytest-3.10.0, py-1.7.0, pluggy-0.8.0 rootdir: /Users/gsnyder/Projects/hub-rest-api-python-test, inifile: plugins: requests-mock-1.5.2 collected 44 items test_hub_rest_api_python.py ........EEEEEEEEEEEE.E.......EE..EEEEE...... [100%] ====================================================================================== ERRORS ======================================================================================= ______________________________________________________________________ ERROR at setup of test_get_policy_by_id ______________________________________________________________________ file /Users/gsnyder/Projects/hub-rest-api-python-test/test/test_hub_rest_api_python.py, line 230 def test_get_policy_by_id(requests_mock, mock_hub_instance, a_test_policy): file /Users/gsnyder/Projects/hub-rest-api-python-test/test/test_hub_rest_api_python.py, line 90 @pytest.fixture() def a_test_policy(policy_info_json): file /Users/gsnyder/Projects/hub-rest-api-python-test/test/test_hub_rest_api_python.py, line 86 @pytest.fixture() def policy_info_json(shared_datadir): E fixture 'shared_datadir' not found > available fixtures: a_test_policy, a_test_policy_for_create_or_update, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, mock_hub_instance, mock_hub_instance_using_api_token, monkeypatch, no_roles_roles, no_roles_user, policy_info_json, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, requests_mock, sample_bom_component_json, sample_snippet_match_json, sysadmin_roles, sysadmin_user, test_vulnerability_info, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory, unreviewed_snippet_json > use 'pytest --fixtures [testpath]' for help on them.
@flichtenheld
Copy link
Contributor Author

I added a new test dependency on pytest-datadir (see requirements.txt). From your output you haven't installed that, yet. That is the pytest plugin that provides the shared_datadir fixture.

@gsnyder2007
Copy link
Contributor

That was it, thanks.

@gsnyder2007 gsnyder2007 merged commit 4d11709 into blackducksoftware:master Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants