Hi,
I am writing a pytest for sgtk.
So, the main code contains sgtk.platform.current_engine()
command, to get the engine and the context from Maya for the selected task.
In the test setUp, im creating a new engine, here is the code.
tk = sgtk.sgtk_from_path("project_path")
sa = sgtk.authentication.ShotgunAuthenticator()
user = sa.get_user()
sgtk.set_authenticated_user(user)
ctx = tk.context_from_path(self.file_path)
self.current_engine = sgtk.platform.start_engine('tk-maya', tk, ctx)
When i run the test, it throws the below error.
engine_name = 'tk-maya'
tk = <Sgtk Core v0.20.6@0x7f551aa48c10 Config project_path>
old_context = None
new_context = <Sgtk Context: project_data{}>
def _start_engine(engine_name, tk, old_context, new_context):
"""
Starts an engine for a given Toolkit instance and context.
:param engine_name: Name of the engine to start.
:param tk: Toolkit instance.
:type tk: :class:`~sgtk.Sgtk`
:param old_context: Context before the context change.
:type old_context: :class:`~sgtk.Context`
:param new_context: Context after the context change.
:type new_context: :class:`~sgtk.Context`
:returns: A new sgtk.platform.Engine object.
"""
# first ensure that an engine is not currently running
if current_engine():
raise TankError(
"An engine (%s) is already running! Before you can start a new engine, "
"please shut down the previous one using the command "
> "tank.platform.current_engine().destroy()." % current_engine()
)
E tank.errors.TankError: An engine (<Sgtk Engine 0x7f552764cd50: tk-maya, env: shot_step>) is already running! Before you can start a new engine, please shut down the previous one using the command tank.platform.current_engine().destroy().
project_path/install/core/python/tank/platform/engine.py:3146: TankError
The test setUp code runs fine and creates a new engine, but when it tries to access the main code, and reach sgtk.platform.current_engine()
this line, it throws the error.
So, sgtk.platform.current_engine()
is supposed to retrieve the current engine right? or am i doing anything wrong in writing the test?