How do I check if a function is called in a function or not, in python? No mock or unittest.
<p>I just want to check whether a particular function is called by other function or not. If yes then I have to store it in a different category and the function that does not call a particular function will be stored in different category. 
I have 3 .py files with classes and functions in them. I need to check each and every function. e.g. let's say a function trial(). If a function calls this function, then that function is in example category else non-example.</p>

<p>I have no idea what you are asking, but even if it is be <a href="http://stackoverflow.com/questions/2654113/python-how-to-get-the-callers-method-name-in-the-called-method">technically possible</a>, the one and only answer: don't do that.</p>

<p>If your design is as such that method A needs to know whether it was called from method B or C; then your design is most likely ... <strong>broken</strong>. Having such dependencies within your code will <em>quickly</em> turn the whole thing un-maintainable. Simply because you will very soon be constantly asking yourself "that path seems fine, but will happen over here?"</p>

<p>One way out of that: create <strong>different</strong> methods; so that B can call something else as C does; but of course, you should still extract the common parts into <em>one</em> method.</p>

<p>Long story short: my non-answer is: take your current design; and have some other people review it. As you should step back from whatever you are doing right now; and find a way to it differently! You know, most of the times, when you start thinking about strange/awkward ways to solve a problem within your current code, the <em>real</em> problem <em>is</em> your current code.</p>

<p>EDIT: given your comments ... The follow up questions would be: what is the purpose of this classification? How often will it need to take place? You know, will it happen only once (then manual counting might be an option), or after each and any change? For the "manual" thing - ideas such as pycharm are pretty good in analyzing python source code, you can do simple things like "search usages in workspaces" - so the IDE lists you all those methods that invoke some method A. But of course, that works only for one <strong>level</strong>. </p>

<p>The other option I see: write some test code that imports all your methods; and then see how far the <a href="http://The%20follow%20up%20question%20would%20be:%20what%20is%20the%20purpose%20of%20this%20classification?%20How%20often%20will%20it%20need%20to%20take%20place?%20You%20know,%20will%20it%20happen%20only%20once%20(then%20manual%20counting%20might%20be%20an%20option),%20or%20after%20each%20and%20any%20change?%20For%20the%20%22manual%22%20thing%20-%20ideas%20such%20as%20pycharm%20are%20pretty%20good%20in%20analyzing%20python%20source%20code,%20you%20can%20do%20simple%20things%20like%20%22search%20usages%20in%20workspaces%22%20-%20so%20the%20IDE%20lists%20you%20all%20those%20methods%20that%20invoke%20some%20method%20A.%20But%20of%20course,%20that%20works%20only%20for%20one%20**level**.%20The%20other%20option%20I%20see:%20write%20some%20test%20code%20that%20imports%20all%20your%20methods;%20http://stackoverflow.com/questions/427453/how-can-i-get-the-source-code-of-a-python-function">inspect</a> module helps you. Probably you could really iterate through a complete method body and simply search for matching method names. </p>

python