You have to import specific class (or classes) under the Module. See the code snippet below.I have explained the logic below the code.
from src.main.core.pageobjects.Module.module1 import Module1
from src.main.core.pageobjects.Module.module2 import Module2
Inside the Module, I created two python files: module 1 and module 2; in module1, I created a class - Module1; in module2, I created a class - Module 2; and then I used the below code snippet to import the two classes in the package
src.tests.BaseTest
Click the link for the project structure screenshot. How to import a module from different directory with Python 3?
See the python codes for module1, module2, and logintest under BaseTest Module.
module1.py
class Module1(object):
def init(self):
print('This is a module 1 example')
def print_info(self):
print("this is module 1 print statement")
module2.py
class Module2(object):
def init(self):
print('This is a module 2 example')
def print_info(self):
print("this is module 2 print statement")
logintest.py under src.tests.BaseTest module
from src.main.core.pageobjects.Module.module1 import Module1
from src.main.core.pageobjects.Module.module2 import Module2
m1=Module1()
m2=Module2()
m1.print_info()
m2.print_info()
Run the logintest.py and see the result. The result is from module1 and module2 in the src.main.core.pageobjects.Module package.
C:\Python36\python.exe C:/Users/SeleniumMaster/PycharmProjects/ProjectDir/src/tests/BaseTest/logintest.py
This is a module 1 example
This is a module 2 example
this is module 1 print statement
this is module 2 print statement
Process finished with exit code 0
import os, import sys, import unittest, from selenium import webdriver, from .main.pageobjects.Module import *