Unfortunately, there's no way to detect the parent context in a trigger. Every time you enter a trigger context, the previous heap and stack is "set aside", so that all you can see is your own execution context. I explored this concept more in this answer if you're interested in further reading. My recommended approach if you're concerned about this is to put in a dead-man-switch style in your trigger handler that must be explicitly set to true in order to run the trigger. This would make sure that you're only testing the trigger when you intend to. Something like this:
public static Boolean skipTrigger = Test.isRunningTest();
public void handleTrigger(...) {
if(skipTrigger) {
return;
}
...
If you have a central testing utility, you can enable the triggers there as part of your startup routine:
public static void loadData() {
SomeTriggerHandler.skipTrigger = false;
...
}
We have a framework like this because it standardizes our unit tests to all use the same data:
@isTest public class TestingFramework {
// static variables to hold common test data here
public static Account ...;
public static Contact ...;
...
// This is called from a @testSetup method in each unit test class
// Note that we also skip the triggers here, too...
public static void testSetup() {
Test.startTest(); // Don't let testSetup eat your governor limits
...
}
// Load things we need to know during testing, like Record Type IDs.
public static void initialize() {
...
}
static {
initialize();
}
// Load data; this is called at start of each unit test
public static void loadData() {
SomeTriggerHandler.skipTrigger = false;
...
}
...
}
Other possible methods are available as well, but the point is you can avoid running your triggers with some carefully designed programming choices.