I think the software behaviour you are observing may be by design and is documented in Displaying Model Data.
Add To Display has no effect outside ModelBuilder. When running a
model tool from its dialog box or the Python window, the Add To
Display setting will not be honored. To add model data variables to
the display when running the model from its dialog box or the Python
window, make the data variable a model parameter, then enable the Add
results of geoprocessing operations to the display option from the
Standard toolbar: Geoprocessing > Geoprocessing Options > Add results
of geoprocessing operations to the display.
Edit: I checked the help for the calculate Value tool. It says: "Variables created in ModelBuilder can be used by this tool, but variables desired for use in the expression parameter cannot be connected to the Calculate Value tool. To use them in the expression, enclose the variable name in percent signs (%). For example, if you want to divide a variable named 'Input' by 100, your expression would be %Input%/100." So, ModelBuilder parameter names have to be surrounded by percent signs to be passed into the Calculate Value tool (It has to be %String%, not String). I have changed the code to show the correct syntax.
The String parameter is never Null, it is initialized as '', so the condition has been change to only return False when values of String are greater than ''. It returns true if String == ''.
You have several problems. In Python you must set up a def function to use a code_block. I have flipped your test logic so that it now tests for actual string values and not Null values. ModelBuilder may return '' for what you consider to be a Null String parameter value. So you may need to change the test to be just values greater than '', not values greater than or equal to ''. None should used to test for real Null values if you are dealing with field values from a table or a parameter from a script tool interface. You are also missing a colon at the end of your if statement as kttii mentioned. Also, this is setting a Boolean parameter based on the Data Type value you have chosen, not a text string, so your return values are wrong and you need to change them to return real Boolean values.
So the expression must change to:
nullTest(%String%)
So the code_block code must change to:
def nullTest(String):
print("The value of String is {0}".format(String))
if String > '':
return False
else:
return True
Best Answer
You can use the Get Count tool as a precondition to a tool. In the model below the buffer tool will only run if count is greater than zero and it's only greater than zero if the select by attribute tool actually selects anything.