Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've been trying to use TestProject OpenSDK for Python to generate HTML test reports for my automated tests (with pytest), but I'm getting the following error: No module named 'src.testproject'.

I've followed the directions laid out on the project's GitHub: https://github.com/testproject-io/python-opensdk but I'm not sure what the problem is.

All my fixtures are in a single file called conftest.py. The code is below.

Python
import pytest
import json

from src.testproject.sdk.drivers import webdriver

CONFIG_PATH = 'tests/config.json'
DEFAULT_WAIT_TIME = 10
SUPPORTED_BROWSERS = ['chrome','firefox']

@pytest.fixture(scope='session')
def config():
  with open(CONFIG_PATH) as config_file:
    data = json.load(config_file)
  return data

@pytest.fixture(scope='session')
def config_browser(config):
  if 'browser' not in config:
    raise Exception('The config file does not contain "browser"')
  elif config['browser'] not in SUPPORTED_BROWSERS:
    raise Exception(f'"{config["browser"]}" is not a supported browser')
  return config['browser']

@pytest.fixture(scope='session')
def config_wait_time(config):
  return config['wait_time'] if 'wait_time' in config else DEFAULT_WAIT_TIME

@pytest.fixture
def browser(config_browser, config_wait_time):
  if config_browser == 'chrome':
    driver = webdriver.Chrome(token='6oBP2BZTPq9zluYpix_3sbwJzP4w005KZOn5bsrMzF01')
  elif config_browser == 'firefox':
    driver = webdriver.Firefox(token='6oBP2BZTPq9zluYpix_3sbwJzP4w005KZOn5bsrMzF01')
  else:
    raise Exception(f'"{config["browser"]}" is not supported')

  driver.implicitly_wait(config_wait_time)
  yield driver
  driver.quit()


The import statement at the top is consistent with the instructions, and I made the necessary changes to the "browser" fixture (the last fixture in the file) to the effect of passing a developer token as an argument to the driver constructor.

The files for TestProject are not in the same directory as my test project. The pip installer put them in my Python distribution directory on my C: drive, so I'm not sure how to properly add this package as a dependency.

What I have tried:

I tried copying the src directory (which contains testproject) from it's location on my C: drive (C:\Python39\Lib\site-packages) directly to the tests directory, but testproject needs a lot more stuff that's also in the site-packages directory. So instead of copying everything I need to make it work out of site-packages, what do I need to do? Can I put the whole path into the import statement somehow?

SOLVED

I added the following line of code to the file conftest.py:


Python
sys.path.append("C:\\Python39\\Lib\\site-packages")



I can now generate human-readable test reports in HTML format.
Posted
Updated 4-Nov-21 15:00pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900